Skip to content

Commit a4660af

Browse files
Propagate constant in result of inline match (#18455)
Fixes #13161
2 parents 2ad16cd + 2b9a62b commit a4660af

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,12 @@ class Inliner(val call: tpd.Tree)(using Context):
877877
}
878878
case _ => rhs0
879879
}
880-
val (usedBindings, rhs2) = dropUnusedDefs(caseBindings, rhs1)
881-
val rhs = seq(usedBindings, rhs2)
880+
val rhs2 = rhs1 match {
881+
case Typed(expr, tpt) if rhs1.span.isSynthetic => constToLiteral(expr)
882+
case _ => constToLiteral(rhs1)
883+
}
884+
val (usedBindings, rhs3) = dropUnusedDefs(caseBindings, rhs2)
885+
val rhs = seq(usedBindings, rhs3)
882886
inlining.println(i"""--- reduce:
883887
|$tree
884888
|--- to:

tests/pos/i13161.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
transparent inline def f: String =
2+
inline 10 match
3+
case _ =>
4+
inline Some["foo"]("foo") match
5+
case Some(x) => x
6+
7+
def test =
8+
inline val failMsg = f

0 commit comments

Comments
 (0)