Commit f8159a3
authored
Although the current local class implementation is still unsound, this
PR should bring back the warning.
Fix #22051
```scala
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
```
```scala
-- [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`
```
File tree
2 files changed
+22
-6
lines changed- compiler/src/dotty/tools/dotc/transform
- tests/warn
2 files changed
+22
-6
lines changedLines changed: 5 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | | - | |
| 59 | + | |
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
370 | | - | |
| 369 | + | |
371 | 370 | | |
372 | 371 | | |
373 | 372 | | |
| |||
392 | 391 | | |
393 | 392 | | |
394 | 393 | | |
395 | | - | |
| 394 | + | |
396 | 395 | | |
397 | 396 | | |
398 | | - | |
| 397 | + | |
399 | 398 | | |
400 | 399 | | |
401 | 400 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
0 commit comments