Skip to content

Commit 96dd7fd

Browse files
committed
Warn on failed switch optimization
Warn if a match is @switch annotated but we could not transform code to a switch.
1 parent 2e7294c commit 96dd7fd

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,18 @@ object PatMat {
507507
patmatch.println(i"Nodes for $tree:${show(raw)}")
508508
val specialized = specialize(raw)
509509
patmatch.println(s"Specialized: ${show(specialized)}")
510-
emit(specialized)
510+
val result = emit(specialized)
511+
512+
tree.selector match {
513+
case Typed(_, tpt) if tpt.tpe.hasAnnotation(defn.SwitchAnnot) =>
514+
result match {
515+
case _: Match | Block(_, _: Match) =>
516+
case _ => ctx.warning("could not emit switch for @switch annotated match", tree.pos)
517+
}
518+
case _ =>
519+
}
520+
521+
result
511522
}
512523
}
513524
}

0 commit comments

Comments
 (0)