You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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. ]
The text was updated successfully, but these errors were encountered:
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.
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. ]
The text was updated successfully, but these errors were encountered: