diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 6cdd0150518b..d9c857279266 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1227,13 +1227,21 @@ class Namer { typer: Typer => case pt: MethodOrPoly => 1 + extensionParamsCount(pt.resType) case _ => 0 val ddef = tpd.DefDef(forwarder.asTerm, prefss => { + val forwarderCtx = ctx.withOwner(forwarder) val (pathRefss, methRefss) = prefss.splitAt(extensionParamsCount(path.tpe.widen)) val ref = path.appliedToArgss(pathRefss).select(sym.asTerm) - ref.appliedToArgss(adaptForwarderParams(Nil, sym.info, methRefss)) - .etaExpandCFT(using ctx.withOwner(forwarder)) + val rhs = ref.appliedToArgss(adaptForwarderParams(Nil, sym.info, methRefss)) + .etaExpandCFT(using forwarderCtx) + if forwarder.isInlineMethod then + // Eagerly make the body inlineable. `registerInlineInfo` does this lazily + // but it does not get evaluated during typer as the forwarder we are creating + // is already typed. + val inlinableRhs = PrepareInlineable.makeInlineable(rhs)(using forwarderCtx) + PrepareInlineable.registerInlineInfo(forwarder, inlinableRhs)(using forwarderCtx) + inlinableRhs + else + rhs }) - if forwarder.isInlineMethod then - PrepareInlineable.registerInlineInfo(forwarder, ddef.rhs) buf += ddef.withSpan(span) if hasDefaults then foreachDefaultGetterOf(sym.asTerm, diff --git a/tests/pos-macros/i14131.scala b/tests/pos-macros/i14131.scala new file mode 100644 index 000000000000..76c01839a17f --- /dev/null +++ b/tests/pos-macros/i14131.scala @@ -0,0 +1,11 @@ +class Dog: + inline given bark(using msg: String = "Woof!"): String = s"bark: $msg" + +class Wolf: + private val dog: Dog = Dog() + export dog.given + +def test = + val w = Wolf() + import w.given + summon[String] diff --git a/tests/pos/i16469.scala b/tests/pos/i16469.scala new file mode 100644 index 000000000000..1aaa381bb7e2 --- /dev/null +++ b/tests/pos/i16469.scala @@ -0,0 +1,15 @@ +class Context { + def normalMethod(): String = "normal" + inline def inlineMethod(): String = "inline" +} + +class Script(ctx: Context) { + export ctx.* + normalMethod() + inlineMethod() +} + +class MyScript(context: Context) extends Script(context) { + normalMethod() + inlineMethod() +}