diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index d57e41ed15de..b245b9ac41f7 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -282,14 +282,7 @@ class ReifyQuotes extends MacroTransform { val tpe = MethodType(defn.SeqType.appliedTo(defn.AnyType) :: Nil, tree.tpe.widen) val meth = ctx.newSymbol(lambdaOwner, UniqueName.fresh(nme.ANON_FUN), Synthetic | Method, tpe) - val closure = Closure(meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth)).withSpan(tree.span) - - enclosingInlineds match { - case enclosingInline :: _ => - // In case a tree was inlined inside of the quote and we this closure corresponds to code within it we need to keep the inlined node. - Inlined(enclosingInline, Nil, closure)(ctx.withSource(lambdaOwner.topLevelClass.source)) - case Nil => closure - } + Closure(meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth)).withSpan(tree.span) } private def transformWithCapturer(tree: Tree)(capturer: mutable.Map[Symbol, Tree] => Tree => Tree)(implicit ctx: Context): Tree = { diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index f91c623102cd..5c87866c4c3d 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1138,16 +1138,22 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { } override def typedIdent(tree: untpd.Ident, pt: Type)(using Context): Tree = - tryInline(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt) + checkStaging(tryInline(tree.asInstanceOf[tpd.Tree]) `orElse` super.typedIdent(tree, pt)) override def typedSelect(tree: untpd.Select, pt: Type)(using Context): Tree = { assert(tree.hasType, tree) val qual1 = typed(tree.qualifier, selectionProto(tree.name, pt, this)) val res = constToLiteral(untpd.cpy.Select(tree)(qual1, tree.name).withType(tree.typeOpt)) ensureAccessible(res.tpe, tree.qualifier.isInstanceOf[untpd.Super], tree.sourcePos) - res + checkStaging(res) } + private def checkStaging(tree: Tree): tree.type = + val sym = tree.symbol + if sym == defn.InternalQuoted_exprQuote || sym == defn.InternalQuoted_typeQuote then + ctx.compilationUnit.needsStaging = true + tree + override def typedIf(tree: untpd.If, pt: Type)(using Context): Tree = typed(tree.cond, defn.BooleanType) match { case cond1 @ ConstantValue(b: Boolean) => diff --git a/tests/pos-macros/i3898c/quoted_1.scala b/tests/disabled/pos-macros/i3898c/quoted_1.scala similarity index 100% rename from tests/pos-macros/i3898c/quoted_1.scala rename to tests/disabled/pos-macros/i3898c/quoted_1.scala diff --git a/tests/pos-macros/i3898c/quoted_2.scala b/tests/disabled/pos-macros/i3898c/quoted_2.scala similarity index 100% rename from tests/pos-macros/i3898c/quoted_2.scala rename to tests/disabled/pos-macros/i3898c/quoted_2.scala diff --git a/tests/pos-macros/i7322/Macro_1.scala b/tests/pos-macros/i7322/Macro_1.scala new file mode 100644 index 000000000000..296733ab36cf --- /dev/null +++ b/tests/pos-macros/i7322/Macro_1.scala @@ -0,0 +1,7 @@ +import scala.quoted.{ QuoteContext, Expr, Type } + +trait M[T] { + def f: Any +} + +inline def g[T: Type](em: Expr[M[T]])(using QuoteContext) = '{$em.f} \ No newline at end of file diff --git a/tests/pos-macros/i7322/Test_2.scala b/tests/pos-macros/i7322/Test_2.scala new file mode 100644 index 000000000000..81ca4d803986 --- /dev/null +++ b/tests/pos-macros/i7322/Test_2.scala @@ -0,0 +1,3 @@ +import scala.quoted.{ QuoteContext, Expr } + +def h(m: Expr[M[String]])(using QuoteContext): Expr[Any] = g(m) \ No newline at end of file diff --git a/tests/pos-macros/i7343/Macro_1.scala b/tests/pos-macros/i7343/Macro_1.scala new file mode 100644 index 000000000000..6e5b31c12e27 --- /dev/null +++ b/tests/pos-macros/i7343/Macro_1.scala @@ -0,0 +1,7 @@ +import scala.quoted.{ QuoteContext, Expr } + +trait M { + def f: Any +} + +inline def g(em: Expr[M])(using QuoteContext) = '{$em.f} \ No newline at end of file diff --git a/tests/pos-macros/i7343/Test_2.scala b/tests/pos-macros/i7343/Test_2.scala new file mode 100644 index 000000000000..b3f482a0e0b6 --- /dev/null +++ b/tests/pos-macros/i7343/Test_2.scala @@ -0,0 +1,3 @@ +import scala.quoted.{ QuoteContext, Expr } + +def h(m: Expr[M])(using QuoteContext): Expr[Any] = g(m) \ No newline at end of file diff --git a/tests/pos-macros/i7343b/Macro_1.scala b/tests/pos-macros/i7343b/Macro_1.scala new file mode 100644 index 000000000000..044a1f04382a --- /dev/null +++ b/tests/pos-macros/i7343b/Macro_1.scala @@ -0,0 +1 @@ +inline def g(using scala.quoted.QuoteContext) = '{1} diff --git a/tests/pos-macros/i7343b/Test_2.scala b/tests/pos-macros/i7343b/Test_2.scala new file mode 100644 index 000000000000..045abb5e3be9 --- /dev/null +++ b/tests/pos-macros/i7343b/Test_2.scala @@ -0,0 +1 @@ +def h(using scala.quoted.QuoteContext) = g