Closed
Description
Compiler version
3.0.0-RC1 with Scala.JS 1.5.0
Minimized code
This reproduction requires Scala.JS 1.5.0:
import scalajs.js.UndefOr
final class X[+A] {
def hmmm: UndefOr[A] = ???
}
I tried to make a reproduction without Scala.JS (see below) but I couldn't get the bug to occur.
package object js {
import scala.annotation.unchecked.uncheckedVariance
sealed trait |[A, B]
type UndefOr[+A] = (A @uncheckedVariance) | Unit
}
import js.UndefOr
final class X[+A] {
def hmmm: UndefOr[A] = ???
}
Output
[error] 4 | def hmmm: UndefOr[A] = ???
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] |covariant type A occurs in invariant position in type => scala.scalajs.js.UndefOr[A] of method hmmm
Expectation
It should compile (and does with Scala 2.x) because UndefOr
is covariant.
/cc @sjrd