From ea5582e14f5b14f5e1425ea93344b51233fa35ce Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 14 Aug 2023 11:58:41 +0200 Subject: [PATCH] Handle macro dependencies through class of `this` Fixes #18393 [Cherry-picked 671f755403b5f575861414e6c9bc82e16034d6d8] --- compiler/src/dotty/tools/dotc/inlines/Inliner.scala | 2 ++ tests/pos-macros/i18393/Inline_2.scala | 8 ++++++++ tests/pos-macros/i18393/Macro_1.scala | 7 +++++++ tests/pos-macros/i18393/Test_2.scala | 5 +++++ 4 files changed, 22 insertions(+) create mode 100644 tests/pos-macros/i18393/Inline_2.scala create mode 100644 tests/pos-macros/i18393/Macro_1.scala create mode 100644 tests/pos-macros/i18393/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala index 608ac311a410..0d481ee8e0be 100644 --- a/compiler/src/dotty/tools/dotc/inlines/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/inlines/Inliner.scala @@ -1067,6 +1067,8 @@ class Inliner(val call: tpd.Tree)(using Context): tree match { case tree: RefTree if tree.isTerm && level == -1 && tree.symbol.isDefinedInCurrentRun && !tree.symbol.isLocal => foldOver(tree.symbol :: syms, tree) + case _: This if level == -1 && tree.symbol.isDefinedInCurrentRun => + tree.symbol :: syms case _: TypTree => syms case _ => foldOver(syms, tree) } diff --git a/tests/pos-macros/i18393/Inline_2.scala b/tests/pos-macros/i18393/Inline_2.scala new file mode 100644 index 000000000000..66fc9b9a135a --- /dev/null +++ b/tests/pos-macros/i18393/Inline_2.scala @@ -0,0 +1,8 @@ +package user + +import defn.Macro + +object Inline extends Macro { + inline def callMacro(): Int = + ${ this.impl() } +} diff --git a/tests/pos-macros/i18393/Macro_1.scala b/tests/pos-macros/i18393/Macro_1.scala new file mode 100644 index 000000000000..fe99162bdf84 --- /dev/null +++ b/tests/pos-macros/i18393/Macro_1.scala @@ -0,0 +1,7 @@ +package defn + +import scala.quoted.* + +abstract class Macro { + def impl()(using Quotes): Expr[Int] = '{1} +} diff --git a/tests/pos-macros/i18393/Test_2.scala b/tests/pos-macros/i18393/Test_2.scala new file mode 100644 index 000000000000..666bf5fd379f --- /dev/null +++ b/tests/pos-macros/i18393/Test_2.scala @@ -0,0 +1,5 @@ +package user + +object Test { + Inline.callMacro() +}