Skip to content
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

Run#compiles incorrectly returns false for symbols in annotation arguments #7758

Open
scabug opened this issue Aug 16, 2013 · 1 comment
Open
Milestone

Comments

@scabug
Copy link

scabug commented Aug 16, 2013

I also notice that "currentRun.compiles()" is broken for symbols of trees defined in annotations of top-level classes.
class foo(x: Any) extends annotation.StaticAnnotation

@foo({class C; ()}) trait A
You can see the problem by calling `companionSymbolOf` during Namers:
~/code/scala git diff
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tool
index cac6bd2..89a2f2f 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala
@@ -258,11 +258,15 @@ trait Namers extends MethodSynthesis {
             returnContext = context.make(tree)
           case _ =>
         }
+        if (tree.symbol != null && tree.symbol != NoSymbol)
+          companionSymbolOf(tree.symbol, this.context)
+
         returnContext
       }
       tree.symbol match {
         case NoSymbol => try dispatch() catch typeErrorHandler(tree, this.context)
-        case sym      => enterExistingSym(sym)
+        case sym      =>
+          enterExistingSym(sym)
       }
     }

@@ -1703,7 +1707,7 @@ trait Namers extends MethodSynthesis {
     // SI-7264 Force the info of owners from previous compilation runs.
     //         Doing this generally would trigger cycles; that's what we also
     //         use the lower-level scan through the current Context as a fall back.
-    if (!currentRun.compiles(owner)) owner.initialize
+    if (!owner.ownerChain.exists(_.isLocalDummy) && !currentRun.compiles(owner)) owner.init
     original.companionSymbol orElse {

That diff also has an idea for a workaround for that case (which is being explored in the experimental Namer in macro paradise that calls this indirectly through companionSymbolOf.:

https://github.com/scalamacros/paradise/blob/2.10.3/plugin/src/main/scala/org/scalalang/macroparadise/typechecker/Namers.scala#L152)

@scabug
Copy link
Author

scabug commented Aug 16, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7758?orig=1
Reporter: @retronym
Affected Versions: 2.10.2

@SethTisue SethTisue added this to the Backlog milestone Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants