Skip to content

Nothing does not conform to arbitrary type parameter #9453

Open
@scabug

Description

@scabug
trait Stuff[A]
def take[A](st: Stuff[A]): Stuff[A] = st

take(??? : Stuff[Nothing])

Result:

<console>:13: error: type mismatch;
 found   : Stuff[Nothing]
 required: Stuff[A]
Note: Nothing <: A, but trait Stuff is invariant in type A.
You may wish to define A as +A instead. (SLS 4.5)
       take(??? : Stuff[Nothing])
                ^

The error goes away if either:

  • type parameter is explicit (i.e. take[Nothing](??? : Stuff[Nothing]))
  • A is covariant
  • A occurs in covariant position in return type of take or does not occur at all

Original SO question: http://stackoverflow.com/questions/32097291/bizzare-type-inference-limitation-multiple-type-params

Metadata

Metadata

Assignees

No one assigned

    Labels

    fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)infertypelevel

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions