Back to Scala3

E102: Undefined Named Type Parameter

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

3.8.41.3 KB
Original Source

E102: Undefined Named Type Parameter

This error is emitted when a named type argument refers to a type parameter that does not exist in the definition.

When using named type arguments, you must use the exact names of the type parameters as declared in the method or class definition.


Example

scala
import scala.language.experimental.namedTypeArguments

def example[A, B](a: A, b: B): (A, B) = (a, b)

val result = example[A = Int, C = String](1, "hello")

Error

scala
-- [E102] Syntax Error: example.scala:5:34 -------------------------------------
5 |val result = example[A = Int, C = String](1, "hello")
  |                                  ^^^^^^
  |                      Type parameter C is undefined. Expected one of A, B.

Solution

scala
// Use the correct, existing, type parameter name
import scala.language.experimental.namedTypeArguments

def example[A, B](a: A, b: B): (A, B) = (a, b)

val result = example[A = Int, B = String](1, "hello")
<!-- 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>