Skip to content
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

Cast to Null$ in pattern match involving existential type #12702

Closed
lrytz opened this issue Dec 15, 2022 · 1 comment · Fixed by scala/scala#10247
Closed

Cast to Null$ in pattern match involving existential type #12702

lrytz opened this issue Dec 15, 2022 · 1 comment · Fixed by scala/scala#10247

Comments

@lrytz
Copy link
Member

lrytz commented Dec 15, 2022

In both 2.12.17 and 2.13.10

object Test {
  trait MFSS[Self <: MFSS[Self]]
  trait CS extends MFSS[CS]

  trait MFI {
    type ST
  }

  case class MFSD[S <: MFSS[S]](mFI: MFI { type ST = S })

  case object IOS extends MFI {
    type ST = CS
  }

  type SD = MFSD[S] forSome {
    type S <: MFSS[S]
  }

  def bad(sd: SD) = sd.mFI match {
    case ios : IOS.type => println(ios)
  }

  def good1(sd: SD) = (sd.mFI: MFI) match {
    case ios : IOS.type => println(ios)
  }

  def good2(sd: SD) = sd.mFI match {
    case ios @ IOS => println(ios)
  }


  def main(args: Array[String]): Unit = {
    val x = MFSD(IOS)
    good1(x)
    good2(x)
    bad(x)
  }
}
➜ sandbox sc Test.scala && s Test
warning: 1 feature warning; re-run with -feature for details
1 warning
IOS
IOS
java.lang.ClassCastException: class Test$IOS$ cannot be cast to class scala.runtime.Null$ (Test$IOS$ and scala.runtime.Null$ are in unnamed module of loader java.net.URLClassLoader @437da279)
	at Test$.bad(Test.scala:20)
	at Test$.main(Test.scala:36)
@lrytz lrytz added this to the Backlog milestone Dec 15, 2022
@lrytz lrytz self-assigned this Dec 15, 2022
@lrytz
Copy link
Member Author

lrytz commented Dec 16, 2022

Added a test case for the underlying bug here: https://github.com/scala/scala/compare/2.13.x...lrytz:scala:t12702-pending?expand=1

Not sure how to fix that for now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant