From 2b9a62bfdde75d21b352351af05f5ea92bf5906c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Fri, 25 Aug 2023 10:52:12 +0200 Subject: [PATCH] Propagate constant in result of inline match Fixes #13161 --- compiler/src/dotty/tools/dotc/inlines/Inliner.scala | 8 ++++++-- tests/pos/i13161.scala | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/pos/i13161.scala diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index c6465c7d5f51..1fb6e785dd43 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -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: diff --git a/tests/pos/i13161.scala b/tests/pos/i13161.scala new file mode 100644 index 000000000000..4c6b2c4c32d0 --- /dev/null +++ b/tests/pos/i13161.scala @@ -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