Skip to content

Commit

Permalink
Backport "Propagate constant in result of inline match" to LTS (#20666)
Browse files Browse the repository at this point in the history
Backports #18455 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 20, 2024
2 parents bb772f3 + 0fda02c commit 5091333
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -877,8 +877,12 @@ class Inliner(val call: tpd.Tree)(using Context):
}
case _ => rhs0
}
val (usedBindings, rhs2) = dropUnusedDefs(caseBindings, rhs1)
val rhs = seq(usedBindings, rhs2)
val rhs2 = rhs1 match {
case Typed(expr, tpt) if rhs1.span.isSynthetic => constToLiteral(expr)
case _ => constToLiteral(rhs1)
}
val (usedBindings, rhs3) = dropUnusedDefs(caseBindings, rhs2)
val rhs = seq(usedBindings, rhs3)
inlining.println(i"""--- reduce:
|$tree
|--- to:
Expand Down
8 changes: 8 additions & 0 deletions tests/pos/i13161.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
transparent inline def f: String =
inline 10 match
case _ =>
inline Some["foo"]("foo") match
case Some(x) => x

def test =
inline val failMsg = f

0 comments on commit 5091333

Please sign in to comment.