Skip to content

Compiler forgets that scala.scalajs.js.UndefOr is covariant #11865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
japgolly opened this issue Mar 24, 2021 · 3 comments
Closed

Compiler forgets that scala.scalajs.js.UndefOr is covariant #11865

japgolly opened this issue Mar 24, 2021 · 3 comments
Milestone

Comments

@japgolly
Copy link
Contributor

japgolly commented Mar 24, 2021

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

@japgolly
Copy link
Contributor Author

@smarter
Copy link
Member

smarter commented Mar 24, 2021

I don't know what's going on here but you should try again with a nightly since we completely changed how Scala.js unions work in Scala 3 (they're regular Scala 3 unions now): #11671

@japgolly
Copy link
Contributor Author

@smarter You're right! This compiles no problem with 3.0.0-RC2-bin-20210322-4035f51-NIGHTLY

@sjrd sjrd added this to the 3.0.0-RC2 milestone Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants