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

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

-- [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

// 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")