Skip to content

Commit a989bcb

Browse files
committed
Prepare bodies of inline forwarders eagerly
Fixes #16469
1 parent 43d0ec4 commit a989bcb

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,13 +1227,18 @@ class Namer { typer: Typer =>
12271227
case pt: MethodOrPoly => 1 + extensionParamsCount(pt.resType)
12281228
case _ => 0
12291229
val ddef = tpd.DefDef(forwarder.asTerm, prefss => {
1230+
val forwarderCtx = ctx.withOwner(forwarder)
12301231
val (pathRefss, methRefss) = prefss.splitAt(extensionParamsCount(path.tpe.widen))
12311232
val ref = path.appliedToArgss(pathRefss).select(sym.asTerm)
1232-
ref.appliedToArgss(adaptForwarderParams(Nil, sym.info, methRefss))
1233-
.etaExpandCFT(using ctx.withOwner(forwarder))
1233+
val rhs = ref.appliedToArgss(adaptForwarderParams(Nil, sym.info, methRefss))
1234+
.etaExpandCFT(using forwarderCtx)
1235+
if forwarder.isInlineMethod then
1236+
val inlinableRhs = PrepareInlineable.makeInlineable(rhs)(using forwarderCtx)
1237+
PrepareInlineable.registerInlineInfo(forwarder, inlinableRhs)(using forwarderCtx)
1238+
inlinableRhs
1239+
else
1240+
rhs
12341241
})
1235-
if forwarder.isInlineMethod then
1236-
PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs)
12371242
buf += ddef.withSpan(span)
12381243
if hasDefaults then
12391244
foreachDefaultGetterOf(sym.asTerm,

tests/pos/i16469.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Context {
2+
def normalMethod(): String = "normal"
3+
inline def inlineMethod(): String = "inline"
4+
}
5+
6+
class Script(ctx: Context) {
7+
export ctx.*
8+
normalMethod()
9+
inlineMethod()
10+
}
11+
12+
class MyScript(context: Context) extends Script(context) {
13+
normalMethod()
14+
inlineMethod()
15+
}

0 commit comments

Comments
 (0)