diff --git a/compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala b/compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala index 032067eca482..feb93c3c6319 100644 --- a/compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala +++ b/compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala @@ -90,6 +90,9 @@ class CrossStageSafety extends TreeMapWithStages { if level != 0 then cpy.Apply(tree)(cpy.TypeApply(tree.fun)(fun, transformedBody :: Nil), quotes :: Nil) else tpd.Quote(transformedBody).select(nme.apply).appliedTo(quotes).withSpan(tree.span) + case _: DefDef if tree.symbol.isInlineMethod => + tree + case _ if !inQuoteOrSpliceScope => checkAnnotations(tree) // Check quotes in annotations super.transform(tree) @@ -117,8 +120,6 @@ class CrossStageSafety extends TreeMapWithStages { // propagate healed types tree1.withType(tree1.tpt.tpe.appliedTo(tree1.args.map(_.tpe))) case tree1 => tree1 - case tree: DefDef if tree.symbol.is(Inline) && level > 0 => - EmptyTree // Remove inline defs in quoted code. Already fully inlined. case tree: ValOrDefDef => checkAnnotations(tree) healInfo(tree, tree.tpt.srcPos) diff --git a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala index a7e0795ce195..03639c8af689 100644 --- a/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala +++ b/compiler/src/dotty/tools/dotc/transform/FirstTransform.scala @@ -18,6 +18,7 @@ import NameKinds.OuterSelectName import StdNames._ import TypeUtils.isErasedValueType import config.Feature +import inlines.Inlines.inInlineMethod object FirstTransform { val name: String = "firstTransform" diff --git a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala index 0c3a94e7d9cd..581b320ed9df 100644 --- a/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala @@ -103,9 +103,7 @@ class PickleQuotes extends MacroTransform { val pickled = PickleQuotes.pickle(quote1, quotes, contents) transform(pickled) // pickle quotes that are in the contents case tree: DefDef if !tree.rhs.isEmpty && tree.symbol.isInlineMethod => - // Shrink size of the tree. The methods have already been inlined. - // TODO move to FirstTransform to trigger even without quotes - cpy.DefDef(tree)(rhs = defaultValue(tree.rhs.tpe)) + tree case _ => super.transform(tree) } diff --git a/compiler/src/dotty/tools/dotc/transform/Staging.scala b/compiler/src/dotty/tools/dotc/transform/Staging.scala index 581fd2753504..35a67e670457 100644 --- a/compiler/src/dotty/tools/dotc/transform/Staging.scala +++ b/compiler/src/dotty/tools/dotc/transform/Staging.scala @@ -8,6 +8,7 @@ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.Flags._ import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.core.Types._ +import dotty.tools.dotc.inlines.Inlines import dotty.tools.dotc.util.SrcPos import dotty.tools.dotc.transform.SymUtils._ import dotty.tools.dotc.staging.StagingLevel.* @@ -56,7 +57,8 @@ class Staging extends MacroTransform { checker.transform(tree) case _ => } - + } + if !Inlines.inInlineMethod then tree match { case tree: RefTree => assert(level != 0 || tree.symbol != defn.QuotedTypeModule_of, @@ -72,7 +74,7 @@ class Staging extends MacroTransform { case _ => // OK } - } + end checkPostCondition override def run(using Context): Unit = if (ctx.compilationUnit.needsStaging) super.run diff --git a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala index 8c8f0079e868..2a665c478932 100644 --- a/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/BootstrappedOnlyCompilationTests.scala @@ -110,6 +110,8 @@ class BootstrappedOnlyCompilationTests { aggregateTests( compileFilesInDir("tests/neg-macros", defaultOptions.and("-Xcheck-macros")), compileFile("tests/pos-macros/i9570.scala", defaultOptions.and("-Xfatal-warnings")), + compileFile("tests/pos-macros/macro-deprecation.scala", defaultOptions.and("-Xfatal-warnings", "-deprecation")), + compileFile("tests/pos-macros/macro-experimental.scala", defaultOptions.and("-Yno-experimental")), ).checkExpectedErrors() } diff --git a/tests/pos-macros/macro-deprecation.scala b/tests/pos-macros/macro-deprecation.scala new file mode 100644 index 000000000000..ff14f96ac7fa --- /dev/null +++ b/tests/pos-macros/macro-deprecation.scala @@ -0,0 +1,4 @@ +import scala.quoted.* + +inline def f = ${ impl } // error +@deprecated def impl(using Quotes) = '{1} diff --git a/tests/pos-macros/macro-experimental.scala b/tests/pos-macros/macro-experimental.scala new file mode 100644 index 000000000000..dc011f4e45b9 --- /dev/null +++ b/tests/pos-macros/macro-experimental.scala @@ -0,0 +1,5 @@ +import scala.quoted.* +import scala.annotation.experimental + +inline def f = ${ impl } // error +@experimental def impl(using Quotes) = '{1}