Skip to content

Commit efc628e

Browse files
oderskyolsdavis
authored andcommitted
Don't generate CanThrow capabilities for catches with guards
1 parent 13a8b9f commit efc628e

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ class Typer extends Namer
17511751
.withSpan(expr.span)
17521752
val caps =
17531753
for
1754-
CaseDef(pat, _, _) <- cases
1754+
case CaseDef(pat, EmptyTree, _) <- cases
17551755
if Feature.enabled(Feature.saferExceptions) && pat.tpe.widen.isCheckedException
17561756
yield makeCanThrow(pat.tpe.widen)
17571757
caps.foldLeft(expr)((e, g) => untpd.Block(g :: Nil, e))

tests/neg/i13849.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import annotation.experimental
2+
import language.experimental.saferExceptions
3+
4+
@experimental
5+
case class Ex(i: Int) extends Exception(s"Exception: $i")
6+
7+
@experimental
8+
def foo(): Unit throws Ex = throw Ex(1)
9+
10+
@experimental
11+
object Main:
12+
def main(args: Array[String]): Unit =
13+
try
14+
foo() // error
15+
catch
16+
case _: Ex if false => println("Caught")

0 commit comments

Comments
 (0)