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

cannot reflect upon annotations on a trait member #6325

Closed
scabug opened this issue Sep 6, 2012 · 2 comments
Closed

cannot reflect upon annotations on a trait member #6325

scabug opened this issue Sep 6, 2012 · 2 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 6, 2012

scala> class W extends scala.annotation.Annotation
defined class W

scala> trait A {
     | @W val a: Int
     | }
defined trait A

scala> typeOf[A].members.last
res0: $r.intp.global.Symbol = value a

scala> res0.getAnnotations
res1: List[$r.intp.global.AnnotationInfo] = List()
@scabug
Copy link
Author

scabug commented Sep 6, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6325?orig=1
Reporter: @xeno-by

@scabug
Copy link
Author

scabug commented Sep 15, 2012

@xeno-by said (edited on Sep 15, 2012 6:26:48 PM UTC):
This issue exposes two important annotation-related gotchas.

  1. To have an annotation visible by Scala reflection, you need to extend either StaticAnnotation or ClassfileAnnotation. Just Annotation won't cut it.

  2. Annotation on a val is by default added to the underlying field of a val. Since val in question is abstract, there's no underlying field, so the annotation goes to waste. Writing @(W @scala.annotation.meta.getter) would attach the annotation to the getter as desired in this situation.

All in all, knowing these gotchas, it's possible to make abstract annotated vals in traits work as desired. Hence I'm closing this as not a bug, but I'm planning to work on making #1 and #2 more obvious.
#1: http://groups.google.com/group/scala-internals/browse_thread/thread/22fa25dca37db40d
#2: #6375

Discussion: http://groups.google.com/group/scala-internals/browse_thread/thread/6f0e90ae1a81b491

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