diff --git a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala index 50373f044719..dcfc6e1447c3 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -76,6 +76,9 @@ class TreeTypeMap( updateDecls(prevStats.tail, newStats.tail) } + /** If true, stop return Inlined(Empty, _, _) nodes unchanged */ + def stopAtInlinedArgument: Boolean = false + override def transform(tree: tpd.Tree)(using Context): tpd.Tree = treeMap(tree) match { case impl @ Template(constr, parents, self, _) => val tmap = withMappedSyms(localSyms(impl :: self :: Nil)) @@ -107,9 +110,12 @@ class TreeTypeMap( val expr1 = tmap1.transform(expr) cpy.Block(blk)(stats1, expr1) case inlined @ Inlined(call, bindings, expanded) => - val (tmap1, bindings1) = transformDefs(bindings) - val expanded1 = tmap1.transform(expanded) - cpy.Inlined(inlined)(call, bindings1, expanded1) + if stopAtInlinedArgument && call.isEmpty then + inlined + else + val (tmap1, bindings1) = transformDefs(bindings) + val expanded1 = tmap1.transform(expanded) + cpy.Inlined(inlined)(call, bindings1, expanded1) case cdef @ CaseDef(pat, guard, rhs) => val tmap = withMappedSyms(patVars(pat)) val pat1 = tmap.transform(pat) diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 527928a6a462..08ff58e918a2 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -753,7 +753,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { }, oldOwners = inlinedMethod :: Nil, newOwners = ctx.owner :: Nil - )(using inlineCtx) + )(using inlineCtx) { + override def stopAtInlinedArgument: Boolean = true + } // Apply inliner to `rhsToInline`, split off any implicit bindings from result, and // make them part of `bindingsBuf`. The expansion is then the tree that remains. diff --git a/tests/pos/i11866.scala b/tests/pos/i11866.scala new file mode 100644 index 000000000000..8cb281f59338 --- /dev/null +++ b/tests/pos/i11866.scala @@ -0,0 +1,21 @@ +type Callback = CallbackTo[Unit] + +final class CallbackTo[+A] { self => + + def >>[B](y: CallbackTo[B]): CallbackTo[B] = + ??? + + inline def *>[B](z: CallbackTo[B]): CallbackTo[B] = + >>(z) + + def qwe: CallbackTo[A] = { + def x: Callback = ??? + val hmmm = this + + x *> this // was error + x *> self // was error + x *> hmmm // ok + + ??? + } +}