Skip to content

Commit b698ce4

Browse files
committed
Make sure that DropBreaks catch also constant folded statements
1 parent 27b3ce7 commit b698ce4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ object DropBreaks:
2727
/** The number of other references to associated label */
2828
var otherRefs: Int = 0
2929

30+
override def toString() = s"LabelUsage($goto, $enclMeth, returnRefs = $returnRefs, otherRefs = $otherRefs)"
31+
3032
private val LabelUsages = new Property.Key[Map[Symbol, LabelUsage]]
3133
private val ShadowedLabels = new Property.Key[Set[Symbol]]
3234

@@ -70,6 +72,15 @@ class DropBreaks extends MiniPhase:
7072
&& throww.symbol == defn.throwMethod
7173
&& ex.symbol == ex2.symbol && ex.symbol == ex3.symbol =>
7274
Some((ex.symbol, lbl.symbol))
75+
case If(
76+
Apply(Select(ex: Ident, isSameLabelAs), (lbl @ Ident(local)) :: Nil),
77+
Literal(_), // in the case where the value is constant folded
78+
Apply(throww, (ex3: Ident) :: Nil))
79+
if isSameLabelAs == nme.isSameLabelAs && local == nme.local
80+
&& throww.symbol == defn.throwMethod
81+
&& ex.symbol == ex3.symbol
82+
&& expr.tpe.isSingleton =>
83+
Some((ex.symbol, lbl.symbol))
7384
case _ =>
7485
None
7586
end GuardedThrow

0 commit comments

Comments
 (0)