Skip to content

Commit c13fac8

Browse files
committed
Check PCP in annotations
1 parent b47498d commit c13fac8

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
6262
private def nestedScopeCtx(defs: List[Tree])(implicit ctx: Context): Context = {
6363
val nestedCtx = ctx.fresh.setNewScope
6464
defs foreach {
65-
case d: DefTree => nestedCtx.enter(d.symbol)
65+
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol)
6666
case _ =>
6767
}
6868
nestedCtx
@@ -73,7 +73,7 @@ class TreeMapWithImplicits extends tpd.TreeMap {
7373
new TreeTraverser {
7474
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
7575
tree match {
76-
case d: DefTree => nestedCtx.enter(d.symbol)
76+
case d: DefTree if d.symbol.isOneOf(GivenOrImplicit) => nestedCtx.enter(d.symbol)
7777
case _ =>
7878
}
7979
traverseChildren(tree)

compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class PCPCheckAndHeal(@constructorOnly ictx: Context) extends TreeMapWithStages(
3838
transform(tree)(ctx.withSource(tree.source))
3939
else tree match {
4040
case tree: DefDef if tree.symbol.is(Inline) && level > 0 => EmptyTree
41+
case tree: DefTree =>
42+
for (annot <- tree.symbol.annotations)
43+
transform(annot.tree) given ctx.withOwner(tree.symbol)
44+
checkLevel(super.transform(tree))
4145
case _ => checkLevel(super.transform(tree))
4246
}
4347
}

tests/neg/i7052.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
class Test {
3+
def foo(str: String) given QuoteContext = '{
4+
@deprecated(str, "") // error
5+
def bar = ???
6+
}
7+
}

0 commit comments

Comments
 (0)