Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0
    • Fix Version/s: None
    • Component/s: Reflection
    • Labels:
      None

      Description

      import java.lang.Class
      import scala.reflect.mirror._
      import scala.reflect.runtime.Mirror.ToolBox
      import scala.reflect.Code
      
      final class table extends StaticAnnotation
      @table class A
      
      object Test extends App{
        val c = new A
        val s = classToSymbol(classOf[A])
      
        assert( 1 == s.annotations.length ) // FAILS as length is 0 here
      
        val tree = Code.lift{c}.tree
        new ToolBox().typeCheck( tree )
      
        assert( 1 == s.annotations.length ) // SUCCEEDS
      }
      

        Activity

        Hide
        Eugene Burmako added a comment -

        This stuff happens because dereferencing annotations does not trigger symbol completion.

        Show
        Eugene Burmako added a comment - This stuff happens because dereferencing annotations does not trigger symbol completion.
        Hide
        Eugene Burmako added a comment -

        A workaround to this problem is to call whatever triggers the completion before inspecting annotations. E.g. a dummy "s.typeSig" does the trick.

        Show
        Eugene Burmako added a comment - A workaround to this problem is to call whatever triggers the completion before inspecting annotations. E.g. a dummy "s.typeSig" does the trick.
        Hide
        Martin Odersky added a comment -

        I propose to add a new method, getAnnotations, to AbsSymbol that does the forcing. I.e.

        def getAnnotations =

        { initialize; annotations }

        Then remove annotations from api.Symbol, and we should be good.

        [I fear we can't do the forcing for all compiler symbols as that could introduce cycles. So it can be done only in reflection].

        Show
        Martin Odersky added a comment - I propose to add a new method, getAnnotations, to AbsSymbol that does the forcing. I.e. def getAnnotations = { initialize; annotations } Then remove annotations from api.Symbol, and we should be good. [I fear we can't do the forcing for all compiler symbols as that could introduce cycles. So it can be done only in reflection] .
        Show
        Eugene Burmako added a comment - Fixed by https://github.com/scala/scala/commit/1eebc520fc787297718d31c3e3a4fb6a244b1067

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Eugene Burmako
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development