Back to Scala3

E141: Missing Type Parameter In Type App

docs/_docs/reference/error-codes/E141.md

3.8.41.9 KB
Original Source

E141: Missing Type Parameter In Type App

This error occurs when a type constructor that takes type parameters is used without providing all required type arguments in a context where a fully applied type is expected.

This typically happens when a parameterized type like Container[T] is passed to a method expecting a simple type T, but Container is passed without its type argument. The type constructor needs to be fully applied with concrete types to match the expected kind.


Example

scala
object Example:
  class Container[T]

  def process[T] = ???

  def test(): Unit =
    process[Container]

Error

scala
-- [E141] Type Error: example.scala:7:12 ---------------------------------------
7 |    process[Container]
  |            ^^^^^^^^^
  |            Missing type parameter for Example.Container
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | A fully applied type is expected but Example.Container takes 1 parameter
   -----------------------------------------------------------------------------

Solution

scala
// Provide the missing type parameter
object Example:
  class Container[T]

  def process[T] = ???

  def test(): Unit =
    process[Container[Int]]
scala
// Alternative: If higher-kinded type is intended, change the method signature
object Example:
  class Container[T]

  def process[F[_]] = ???

  def test(): Unit =
    process[Container]
<!-- SOURCE-ONLY: Remove the notice below once this page has been manually updated. --> <aside class="warning"> This reference page was created with LLM assistance - the description of the error code may not be accurate or cover all possible scenarios. </aside>