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

symbol.hasAnnotation sometimes returns incorrect result unless symbol.getAnnotations called beforehand #6428

Closed
scabug opened this issue Sep 26, 2012 · 3 comments

Comments

@scabug
Copy link

scabug commented Sep 26, 2012

In some circumstances, calling symbol.hasAnnotation incorrectly returns false, but returns the correct thing if symbol.getAnnotations is called beforehand.

Example program showing bug:

package test
import scala.reflect.runtime._

object Test extends App {
val cx = classOf[X];
val symbol = universe.runtimeMirror(cx.getClassLoader).classSymbol(cx);
val ca = classOf[scala.deprecated];
val a=universe.runtimeMirror(ca.getClassLoader).classSymbol(ca);
println(symbol.hasAnnotation(a));
symbol.getAnnotations;
println(symbol.hasAnnotation(a))
}

@scala.deprecated class X

This prints out "false" then "true".

I note that the symbol.getAnnotations function calls initialize, then returns the annotations internal field, while hasAnnotation just uses the internal field directly.

It all works correctly when I run it from the REPL instead of compiling directly.

[ Sorry for entering it is a blocker when there is a workaround - the web form didn't let me change it. ]

@scabug
Copy link
Author

scabug commented Sep 26, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6428?orig=1
Reporter: Andrew Conway (arc)
Affected Versions: 2.10.0-M7

@scabug
Copy link
Author

scabug commented Sep 26, 2012

@xeno-by said:
Duplicate of #6277.

Good news is that we have a pull request that fixes the underlying problem of both #6277 and this bug, and that I'm doing my best to push it into RC1.

Bad news is that I've removed Symbol.hasAnnotation (though Symbol.annotations is still there). For 2.10.0 we strive for the simplest API possible. In subsequent point releases we plan to expand the API with more convenience methods.

@scabug scabug closed this as completed Sep 26, 2012
@scabug
Copy link
Author

scabug commented Feb 24, 2013

@xeno-by said:
Please note that the fix only works for runtime reflection, not for compile-time reflection used in macros.

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

2 participants