E035: Unbound Wildcard Type

This error is emitted when the wildcard type syntax (_ or ?) is used in a position where it cannot be bound to a concrete type.

Replace the wildcard with a non-wildcard type. If the type doesn't matter, try replacing the wildcard with Any.

This typically happens in:

  • Parameter lists: def foo(x: _) = ...
  • Type arguments in constructors: val foo = List[?](1, 2)
  • Type bounds: def foo[T <: _](x: T) = ...
  • val and def types: val foo: _ = 3

Example

def example(x: ?) = x

Error

-- [E035] Syntax Error: example.scala:1:15 -------------------------------------
1 |def example(x: ?) = x
  |               ^
  |               Unbound wildcard type
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | The wildcard type syntax (_) was used where it could not be bound.
  | Replace _ with a non-wildcard type. If the type doesn't matter,
  | try replacing _ with Any.
  |
  | Examples:
  |
  | - Parameter lists
  |
  |   Instead of:
  |     def foo(x: _) = ...
  |
  |   Use Any if the type doesn't matter:
  |     def foo(x: Any) = ...
  |
  | - Type arguments
  |
  |   Instead of:
  |     val foo = List[?](1, 2)
  |
  |   Use:
  |     val foo = List[Int](1, 2)
  |
  | - Type bounds
  |
  |   Instead of:
  |     def foo[T <: _](x: T) = ...
  |
  |   Remove the bounds if the type doesn't matter:
  |     def foo[T](x: T) = ...
  |
  | - val and def types
  |
  |   Instead of:
  |     val foo: _ = 3
  |
  |   Use:
  |     val foo: Int = 3
   -----------------------------------------------------------------------------

Solution

// Use Any if the type doesn't matter
def example(x: Any) = x
// Use a type parameter for generic behavior
def example[T](x: T): T = x
// Specify a concrete type
def example(x: Int) = x