Skip to content

Commit 2e66407

Browse files
committed
Introduce getAnnotations that triggers symbol completion
Default getter for annotations doesn't perform initialization, hence we've faced the following bug: https://issues.scala-lang.org/browse/SI-5423. One of the approaches to fixing it would be to auto-complete on getter, but according to Martin we'd better not do that because of cycles. That's why I'm just introducing a new, eager, variation of `annotations' and redirecting public API to it. Review by @odersky.
1 parent 263aa2e commit 2e66407

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

src/compiler/scala/reflect/internal/Symbols.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,16 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
12721272
* the annotations attached to member a definition (class, method, type, field).
12731273
*/
12741274
def annotations: List[AnnotationInfo] = _annotations
1275+
1276+
/** This getter is necessary for reflection, see https://issues.scala-lang.org/browse/SI-5423
1277+
* We could auto-inject completion into `annotations' and `setAnnotations', but I'm not sure about that
1278+
* @odersky writes: I fear we can't do the forcing for all compiler symbols as that could introduce cycles
1279+
*/
1280+
def getAnnotations: List[AnnotationInfo] = {
1281+
initialize
1282+
_annotations
1283+
}
1284+
12751285
def setAnnotations(annots: List[AnnotationInfo]): this.type = {
12761286
_annotations = annots
12771287
this

src/library/scala/reflect/api/Symbols.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ trait Symbols { self: Universe =>
7979

8080
/** A list of annotations attached to this Symbol.
8181
*/
82-
def annotations: List[self.AnnotationInfo]
82+
def getAnnotations: List[self.AnnotationInfo]
8383

8484
/** For a class: the module or case class factory with the same name in the same package.
8585
* For all others: NoSymbol

test/files/run/t5423.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
List(table)

test/files/run/t5423.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import java.lang.Class
2+
import scala.reflect.mirror._
3+
import scala.reflect.runtime.Mirror.ToolBox
4+
import scala.reflect.Code
5+
6+
final class table extends StaticAnnotation
7+
@table class A
8+
9+
object Test extends App{
10+
val s = classToSymbol(classOf[A])
11+
println(s.getAnnotations)
12+
}

0 commit comments

Comments
 (0)