diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 79e1b739b542..1bd2da4fed7c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1291,7 +1291,13 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { if (!tree.isInline || ctx.owner.isInlineMethod) // don't reduce match of nested inline method yet super.typedMatchFinish(tree, sel, wideSelType, cases, pt) else { - val selType = if (sel.isEmpty) wideSelType else sel.tpe + def selTyped(sel: Tree): Type = sel match { + case Typed(sel2, _) => selTyped(sel2) + case Block(Nil, sel2) => selTyped(sel2) + case Inlined(_, Nil, sel2) => selTyped(sel2) + case _ => sel.tpe + } + val selType = if (sel.isEmpty) wideSelType else selTyped(sel) reduceInlineMatch(sel, selType, cases.asInstanceOf[List[CaseDef]], this) match { case Some((caseBindings, rhs0)) => // drop type ascriptions/casts hiding pattern-bound types (which are now aliases after reducing the match) @@ -1509,4 +1515,5 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { case _ => None } + } diff --git a/tests/pos/i11291.scala b/tests/pos/i11291.scala new file mode 100644 index 000000000000..13243b82805b --- /dev/null +++ b/tests/pos/i11291.scala @@ -0,0 +1,11 @@ +inline def meth = + val x1 = inline ("a": Any) match + case _: String => "ok" + val x2 = inline { "a": Any } match + case _: String => "ok" + inline s match + case _: String => "ok" + +inline def s = "a": Any + +def test = meth diff --git a/tests/pos/i6781.scala b/tests/pos/i6781.scala new file mode 100644 index 000000000000..f3061f870c95 --- /dev/null +++ b/tests/pos/i6781.scala @@ -0,0 +1,13 @@ +enum Nat { + case Zero + case Succ[N <: Nat](n: N) +} +import Nat._ + +inline def toInt(inline n: Nat): Int = inline n match { + case Zero => 0 + case Succ(n1) => toInt(n1) + 1 +} + +val natTwoA = toInt(Succ[Succ[Zero.type]](Succ(Zero))) +val natTwoB = toInt(Succ(Succ(Zero)): Succ[Succ[Zero.type]])