From b5dcc7df8aa08993f156281395460b13f70d319e Mon Sep 17 00:00:00 2001 From: Emil Ejbyfeldt Date: Sat, 13 Dec 2025 13:01:14 +0100 Subject: [PATCH] Delias in isSimpleThrowable check fixes: #23357 --- .../tools/dotc/transform/TryCatchPatterns.scala | 2 +- tests/run/i24357.scala | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/run/i24357.scala diff --git a/compiler/src/dotty/tools/dotc/transform/TryCatchPatterns.scala b/compiler/src/dotty/tools/dotc/transform/TryCatchPatterns.scala index 095c6af60766..6243f8ac1cad 100644 --- a/compiler/src/dotty/tools/dotc/transform/TryCatchPatterns.scala +++ b/compiler/src/dotty/tools/dotc/transform/TryCatchPatterns.scala @@ -71,7 +71,7 @@ class TryCatchPatterns extends MiniPhase { case _ => isDefaultCase(cdef) } - private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp.stripped match { + private def isSimpleThrowable(tp: Type)(using Context): Boolean = tp.strippedDealias match { case tp @ TypeRef(pre, _) => (pre == NoPrefix || pre.typeSymbol.isStatic) && // Does not require outer class check !tp.symbol.is(Flags.Trait) && // Traits not supported by JVM diff --git a/tests/run/i24357.scala b/tests/run/i24357.scala new file mode 100644 index 000000000000..6b6d46b85963 --- /dev/null +++ b/tests/run/i24357.scala @@ -0,0 +1,15 @@ +class E1 extends Exception +class E2 extends Exception + +type E1or2 = E1 | E2 + +def caughtE1orE2(body: => Nothing): Boolean = + try body + catch + case ex: E1or2 => true + case _ => false + +@main def Test = + assert(caughtE1orE2(throw new E1 {})) + assert(caughtE1orE2(throw new E2 {})) + assert(!caughtE1orE2(throw new Exception {}))