diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index a71fc3d40e92..96253cbc63a8 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -1265,6 +1265,8 @@ object desugar { * $throws[... $throws[A, E1] ... , En]. */ def throws(tpt: Tree, op: Ident, excepts: Tree)(using Context): AppliedTypeTree = excepts match + case Parens(excepts1) => + throws(tpt, op, excepts1) case InfixOp(l, bar @ Ident(tpnme.raw.BAR), r) => throws(throws(tpt, op, l), bar, r) case e => diff --git a/tests/pos/i13816.scala b/tests/pos/i13816.scala new file mode 100644 index 000000000000..0804fc117288 --- /dev/null +++ b/tests/pos/i13816.scala @@ -0,0 +1,35 @@ +import language.experimental.saferExceptions + +class Ex1 extends Exception("Ex1") +class Ex2 extends Exception("Ex2") + +def foo1(i: Int): Unit throws Ex1 throws Ex2 = + if i > 0 then throw new Ex1 else throw new Ex2 + +def foo2(i: Int): Unit throws Ex1 | Ex2 = + if i > 0 then throw new Ex1 else throw new Ex2 + +def foo2a(i: Int): Unit throws (Ex1 | Ex2) = + if i > 0 then throw new Ex1 else throw new Ex2 + +def foo3(i: Int)(using CanThrow[Ex1], CanThrow[Ex2]) = + if i > 0 then throw new Ex1 else throw new Ex2 + +def foo4(i: Int)(using CanThrow[Ex1])(using CanThrow[Ex2]) = + if i > 0 then throw new Ex1 else throw new Ex2 + +//def foo5(i: Int)(using CanThrow[Ex1 & Ex2]) = // does not work: no capability aggregation is supported +// if i > 0 then throw new Ex1 else throw new Ex2 + +def test(): Unit = + try { + foo1(1) + foo2(1) + foo2a(1) + foo3(1) + foo4(1) + //foo5(1) // error + } catch { + case _: Ex1 => + case _: Ex2 => + } \ No newline at end of file