Skip to content

Leave inlined arguments alone in inliner map #11886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 21 additions & 0 deletions tests/pos/i11866.scala
Original file line number Diff line number Diff line change
@@ -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

???
}
}