diff --git a/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala b/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala index 2e03b44c3b1d..154729a877c8 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala @@ -62,7 +62,7 @@ class TreeMapWithImplicits extends tpd.TreeMap { private def nestedScopeCtx(defs: List[Tree])(implicit ctx: Context): Context = { val nestedCtx = ctx.fresh.setNewScope defs foreach { - case d: DefTree => nestedCtx.enter(d.symbol) + case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol) case _ => } nestedCtx @@ -73,7 +73,7 @@ class TreeMapWithImplicits extends tpd.TreeMap { new TreeTraverser { def traverse(tree: Tree)(implicit ctx: Context): Unit = { tree match { - case d: DefTree => nestedCtx.enter(d.symbol) + case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol) case _ => } traverseChildren(tree) diff --git a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala index 90c68d8e5b75..f5951bf12118 100644 --- a/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala +++ b/compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala @@ -38,6 +38,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages( transform(tree)(ctx.withSource(tree.source)) else tree match { case tree: DefDef if tree.symbol.is(Inline) && level > 0 => EmptyTree + case tree: DefTree => + for (annot <- tree.symbol.annotations) + transform(annot.tree) given ctx.withOwner(tree.symbol) + checkLevel(super.transform(tree)) case _ => checkLevel(super.transform(tree)) } } diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index d042966bdc30..1fcf51858e9a 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -19,7 +19,7 @@ import dotty.tools.dotc.ast.tpd import typer.Implicits.SearchFailureType import scala.collection.mutable -import dotty.tools.dotc.core.Annotations.Annotation +import dotty.tools.dotc.core.Annotations._ import dotty.tools.dotc.core.Names._ import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.quoted._ @@ -405,6 +405,14 @@ class ReifyQuotes extends MacroTransform { // TODO move to FirstTransform to trigger even without quotes cpy.DefDef(tree)(rhs = defaultValue(tree.rhs.tpe)) + case tree: DefTree if level >= 1 => + val newAnnotations = tree.symbol.annotations.mapconserve { annot => + val newAnnotTree = transform(annot.tree) given ctx.withOwner(tree.symbol) + if (annot.tree == newAnnotTree) annot + else ConcreteAnnotation(newAnnotTree) + } + tree.symbol.annotations = newAnnotations + super.transform(tree) case _ => super.transform(tree) } diff --git a/tests/neg/i7052.scala b/tests/neg/i7052.scala new file mode 100644 index 000000000000..3c6f932c3bf7 --- /dev/null +++ b/tests/neg/i7052.scala @@ -0,0 +1,7 @@ +import scala.quoted._ +class Test { + def foo(str: String) given QuoteContext = '{ + @deprecated(str, "") // error + def bar = ??? + } +} diff --git a/tests/neg/i7052b.scala b/tests/neg/i7052b.scala new file mode 100644 index 000000000000..d5ef75aa7a79 --- /dev/null +++ b/tests/neg/i7052b.scala @@ -0,0 +1,10 @@ +import scala.quoted._ +class Test { + def foo(str: String) given QuoteContext = '{ + delegate for QuoteContext = ??? + '{ + @deprecated(str, "") // error + def bar = ??? + } + } +} diff --git a/tests/pos/i7052.scala b/tests/pos/i7052.scala new file mode 100644 index 000000000000..765a03c4fe1e --- /dev/null +++ b/tests/pos/i7052.scala @@ -0,0 +1,7 @@ +import scala.quoted._ +class Test { + def foo(str: Expr[String]) given QuoteContext = '{ + @deprecated($str, "") + def bar = ??? + } +}