Back to Scala3

E101: Duplicate Named Type Parameter

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

3.8.41.3 KB
Original Source

E101: Duplicate Named Type Parameter

This error is emitted when a type parameter is defined multiple times in a named type argument list.

When using named type arguments (type parameter names followed by = and a type), each type parameter can only be specified once.


Example

scala
import scala.language.experimental.namedTypeArguments

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

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

Error

scala
-- [E101] Syntax Error: example.scala:5:34 -------------------------------------
5 |val result = example[A = Int, A = String](1, "hello")
  |                                  ^^^^^^
  |                              Type parameter A was defined multiple times.

Solution

scala
// Use each type parameter name only once
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>