타입 매개변수 누락

타입 매개변수 누락 (Missing Type Parameter For)

완전히 적용된 타입이 필요한 자리에 higher-kinded 타입이나 타입 생성자를 사용했을 때 나오는 에러예요.

출처: Scala 3 Reference

본문

완전히 적용된(full applied) 타입이 기대되는 자리에 higher-kinded 타입이나 타입 생성자를 사용하면 이 에러가 발생해요.

타입 생성자(ListOption 같은)는 값 타입으로 쓰이려면 먼저 타입 인자에 적용되어야 해요. 예를 들어 List 자체는 타입 생성자지만, List[Int]는 제대로 된(proper) 타입이에요.

예시

val items: List = List(1, 2, 3)

에러 메시지

-- [E056] Syntax Error: example.scala:1:11 -------------------------------------
1 |val items: List = List(1, 2, 3)
  |           ^^^^
  |           Missing type parameter for List

해결 방법

// Provide the type parameter
val items: List[Int] = List(1, 2, 3)
// Or let the compiler infer the type
val items = List(1, 2, 3)

더 알아보기

  • 타입 매개변수를 명시해 주거나, 컴파일러가 추론하도록 타입 표기를 생략하면 돼요.