Skip to content

Fix #7052: Transform annotations in ReifyQuotes #7053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeMapWithImplicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems to break the originally intended semantics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is supposed to add the missing implicits into the scope. But adding other definitions interacts badly with on of the Yckeck while transforming an annotation containing a definition.

case _ =>
}
nestedCtx
Expand All @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above.

case _ =>
}
traverseChildren(tree)
Expand Down
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/PCPCheckAndHeal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions tests/neg/i7052.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._
class Test {
def foo(str: String) given QuoteContext = '{
@deprecated(str, "") // error
def bar = ???
}
}
10 changes: 10 additions & 0 deletions tests/neg/i7052b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.quoted._
class Test {
def foo(str: String) given QuoteContext = '{
delegate for QuoteContext = ???
'{
@deprecated(str, "") // error
def bar = ???
}
}
}
7 changes: 7 additions & 0 deletions tests/pos/i7052.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._
class Test {
def foo(str: Expr[String]) given QuoteContext = '{
@deprecated($str, "")
def bar = ???
}
}