E095: Expected Type Bound Or Equals

This error is emitted when a type parameter or type member definition has invalid syntax - expecting =, >:, or <: but finding something else.

Type parameters and abstract types may be constrained by type bounds:

  • = for type aliases
  • <: for upper type bounds (subtype constraint)
  • >: for lower type bounds (supertype constraint)

Example

class Container:
  type MyType @

Error

-- [E095] Syntax Error: example.scala:2:14 -------------------------------------
2 |  type MyType @
  |              ^
  |              =, >:, or <: expected, but '@' found
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Type parameters and abstract types may be constrained by a type bound.
  | Such type bounds limit the concrete values of the type variables and possibly
  | reveal more information about the members of such types.
  |
  | A lower type bound B >: A expresses that the type variable B
  | refers to a supertype of type A.
  |
  | An upper type bound T <: A declares that type variable T
  | refers to a subtype of type A.
   -----------------------------------------------------------------------------

Solution

// Use = for type alias
class Container:
  type MyType = Int
// Use <: for upper bound
class Container:
  type MyType <: AnyVal
// Use >: for lower bound
class Container:
  type MyType >: Nothing