-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)typeleveltyper
Milestone
Description
Happening in Scala 2.7.1 and 2.7.2 at least:
scala> trait Test[A]
defined trait Test
scala> trait Test2[+A]
defined trait Test2
scala> def f[A](a:Test[A]):Test[A] = null
f: [A](Test[A])Test[A]
scala> def f2[A](a:Test[A]):Test2[A] = null
f2: [A](Test[A])Test2[A]
scala> val x:Test[Nothing] = null
x: Test[Nothing] = null
scala> f(x)
<console>:8: error: type mismatch;
found : Test[Nothing]
required: Test[A]
f(x)
^
scala> f[Nothing](x)
res2: Test[Nothing] = null
scala> f2(x)
res1: Test2[Nothing] = null
This happens only for A=Nothing. And only if the return type is invariant in a type variable being Nothing. There is probably not much sense in operating on Nothing types, but what is the rationale behind this behaviour?
Metadata
Metadata
Assignees
Labels
fixed in Scala 3This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)typeleveltyper