Skip to content

Commit a039f3c

Browse files
committed
Leave inlined arguemnts alone in inliner map
Fixes #11866
1 parent 0c4321a commit a039f3c

File tree

3 files changed

+33
-4
lines changed

3 files changed

+33
-4
lines changed

compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ class TreeTypeMap(
7676
updateDecls(prevStats.tail, newStats.tail)
7777
}
7878

79+
/** If true, stop return Inlined(Empty, _, _) nodes unchanged */
80+
def stopAtInlinedArgument: Boolean = false
81+
7982
override def transform(tree: tpd.Tree)(using Context): tpd.Tree = treeMap(tree) match {
8083
case impl @ Template(constr, parents, self, _) =>
8184
val tmap = withMappedSyms(localSyms(impl :: self :: Nil))
@@ -107,9 +110,12 @@ class TreeTypeMap(
107110
val expr1 = tmap1.transform(expr)
108111
cpy.Block(blk)(stats1, expr1)
109112
case inlined @ Inlined(call, bindings, expanded) =>
110-
val (tmap1, bindings1) = transformDefs(bindings)
111-
val expanded1 = tmap1.transform(expanded)
112-
cpy.Inlined(inlined)(call, bindings1, expanded1)
113+
if stopAtInlinedArgument && call.isEmpty then
114+
inlined
115+
else
116+
val (tmap1, bindings1) = transformDefs(bindings)
117+
val expanded1 = tmap1.transform(expanded)
118+
cpy.Inlined(inlined)(call, bindings1, expanded1)
113119
case cdef @ CaseDef(pat, guard, rhs) =>
114120
val tmap = withMappedSyms(patVars(pat))
115121
val pat1 = tmap.transform(pat)

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
753753
},
754754
oldOwners = inlinedMethod :: Nil,
755755
newOwners = ctx.owner :: Nil
756-
)(using inlineCtx)
756+
)(using inlineCtx) {
757+
override def stopAtInlinedArgument: Boolean = true
758+
}
757759

758760
// Apply inliner to `rhsToInline`, split off any implicit bindings from result, and
759761
// make them part of `bindingsBuf`. The expansion is then the tree that remains.

tests/pos/i11866.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
type Callback = CallbackTo[Unit]
2+
3+
final class CallbackTo[+A] { self =>
4+
5+
def >>[B](y: CallbackTo[B]): CallbackTo[B] =
6+
???
7+
8+
inline def *>[B](z: CallbackTo[B]): CallbackTo[B] =
9+
>>(z)
10+
11+
def qwe: CallbackTo[A] = {
12+
def x: Callback = ???
13+
val hmmm = this
14+
15+
x *> this // was error
16+
x *> self // was error
17+
x *> hmmm // ok
18+
19+
???
20+
}
21+
}

0 commit comments

Comments
 (0)