Skip to content

Commit c0f7c2a

Browse files
authored
Dealias in isSimpleThrowable check (#24744)
fixes: #24357
2 parents c3f9d62 + b5dcc7d commit c0f7c2a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

compiler/src/dotty/tools/dotc/transform/TryCatchPatterns.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TryCatchPatterns extends MiniPhase {
7171
case _ => isDefaultCase(cdef)
7272
}
7373

74-
private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp.stripped match {
74+
private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp.strippedDealias match {
7575
case tp @ TypeRef(pre, _) =>
7676
(pre == NoPrefix || pre.typeSymbol.isStatic) && // Does not require outer class check
7777
!tp.symbol.is(Flags.Trait) && // Traits not supported by JVM

tests/run/i24357.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class E1 extends Exception
2+
class E2 extends Exception
3+
4+
type E1or2 = E1 | E2
5+
6+
def caughtE1orE2(body: => Nothing): Boolean =
7+
try body
8+
catch
9+
case ex: E1or2 => true
10+
case _ => false
11+
12+
@main def Test =
13+
assert(caughtE1orE2(throw new E1 {}))
14+
assert(caughtE1orE2(throw new E2 {}))
15+
assert(!caughtE1orE2(throw new Exception {}))

0 commit comments

Comments
 (0)