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

Fix #22051: only trust the type application part for case class unapplies #22099

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Dec 3, 2024

Although the current local class implementation is still unsound, this PR should bring back the warning.

Fix #22051

def boundary[T](body: (T => RuntimeException) => T): T =
  case class Break(value: T) extends RuntimeException
  try body(Break.apply)
  catch case Break(t) => t // error: pattern matching on local classes is unsound currently

def test =
  boundary[Int]: EInt =>
    val v: String = boundary[String]: EString =>
      throw EInt(3)
    v.length // a runtime error: java.lang.ClassCastException
-- [E092] Pattern Match Unchecked Warning: tests/neg/i22051.scala:6:13 ---------
6 |  catch case Break(t) => t // error: pattern matching on local classes is unsound currently
  |             ^
  |the type test for Break cannot be checked at runtime because it's a local class
  |
  | longer explanation available when compiling with `-explain`

@noti0na1 noti0na1 requested a review from sjrd December 3, 2024 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unsound compilation of local classes in conjunction with exceptions
2 participants