Details

      Description

      object A {
        @annotation.static final val x = 123
      }
      
      no-symbol does not have an owner
      	at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:48)
      	at scala.tools.nsc.Global.abort(Global.scala:246)
      	at scala.reflect.internal.Symbols$NoSymbol.owner(Symbols.scala:3113)
      	at scala.tools.nsc.backend.icode.Opcodes$opcodes$LOAD_FIELD.<init>(Opcodes.scala:224)
      	at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:130)
      	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:72)
      	at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:72)
      	at scala.collection.immutable.List.foreach(List.scala:309)
      

        Activity

        Hide
        Aleksandar Prokopec added a comment - - edited

        Interesting. I didn't know that val s get transformed into def s directly by the compiler sometimes.

        This, for instance, works:

        object A {
          @annotation.static final val x = {
            "abcdef".length * 123
          }
        }
        
        Show
        Aleksandar Prokopec added a comment - - edited Interesting. I didn't know that val s get transformed into def s directly by the compiler sometimes. This, for instance, works: object A { @annotation.static final val x = { "abcdef".length * 123 } }
        Hide
        Aleksandar Prokopec added a comment -

        I'm not sure in which phase a transformation from a val to def takes place (i.e. where simple constants get inlined into the getter accessor), but wherever it's done, the accessed field of the symbol should be reset to NoSymbol. After all, the method definition x below:

        package <empty> {
          object A extends Object {
            final <stable> <accessor> def x(): Int = 123;
            def <init>(): A.type = {
              A.super.<init>();
              ()
            }
          }
        }
        

        is no longer a getter.

        Show
        Aleksandar Prokopec added a comment - I'm not sure in which phase a transformation from a val to def takes place (i.e. where simple constants get inlined into the getter accessor), but wherever it's done, the accessed field of the symbol should be reset to NoSymbol . After all, the method definition x below: package <empty> { object A extends Object { final <stable> <accessor> def x(): Int = 123; def <init>(): A.type = { A.super.<init>(); () } } } is no longer a getter.
        Hide
        Aleksandar Prokopec added a comment -

        Apparently, this is done in constructors.

        Show
        Aleksandar Prokopec added a comment - Apparently, this is done in constructors .
        Show
        Aleksandar Prokopec added a comment - https://github.com/scala/scala/pull/1217

          People

          • Assignee:
            Aleksandar Prokopec
            Reporter:
            Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development