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

Merged
merged 2 commits into from
Jan 8, 2025

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
@noti0na1 noti0na1 requested a review from dwijnand January 8, 2025 12:12
@noti0na1 noti0na1 assigned dwijnand and unassigned sjrd Jan 8, 2025
@noti0na1 noti0na1 merged commit f8159a3 into scala:main Jan 8, 2025
29 checks passed
@noti0na1 noti0na1 deleted the fix-22051 branch January 8, 2025 13:39
@WojciechMazur WojciechMazur added this to the 3.6.4 milestone Jan 16, 2025
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
4 participants