E214: Illegal Context Bounds

This error is emitted when context bounds are used in a position where they are not allowed.

Context bounds (like T: Ordering) are a shorthand for requiring an implicit instance of a type class for a type parameter. However, they can only be used in certain positions, such as method or class type parameters, not in type alias definitions.


Example

trait Equatable[T]

type Foo[T: Equatable]

Error

-- [E214] Syntax Error: example.scala:3:21 -------------------------------------
3 |type Foo[T: Equatable]
  |            ^^^^^^^^^
  |            Context bounds are not allowed in this position

Solution

Context bounds are allowed in method or class definitions where implicit parameters can be added:

trait Equatable[T]

def foo[T: Equatable](value: T): Unit = ()
trait Equatable[T]

class Foo[T: Equatable](value: T)

For type aliases, you cannot use context bounds. If you need to express a constraint, consider using a class or trait instead:

trait Equatable[T]

trait Foo[T]:
  given Equatable[T] = ???