Skip to content

Passing bounded types as a wildcard #10371

Open
@tindzk

Description

@tindzk

Consider the following example:

case class MyList[T <: String]()
def f[T](value: T): Unit = {} 
f(null.asInstanceOf[MyList[_]])

It fails with the following error:

error: type arguments [_$1] do not conform to class MyList's type parameter bounds [T <: String]
       f(null.asInstanceOf[MyList[_]])

However, the above example does work when either

  • explicitly passing the type: f[MyList[_]](null), or
  • defining the function as def f(value: Any): Unit = {}.

I am not entirely sure whether this is the intended behaviour. In any case, it would be helpful to issue a better error message.

See also com-lihaoyi/Ammonite#629 and typelevel/scala#156.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions