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

Nesting of @static field and separate compilation definition-site and call-site causes compiler crash in icode phase with message "no-symbol does not have an owner" #6236

Closed
scabug opened this issue Aug 14, 2012 · 9 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Aug 14, 2012

scala> object Foo {
     | @annotation.static val foo = 353/0 }
defined module Foo
scala> println(Foo.foo)
ReplGlobal.abort: no-symbol does not have an owner
error: no-symbol does not have an owner
error:
     while compiling: <console>
        during phase: icode
     library version: version 2.10.0-M6
    compiler version: version 2.10.0-M6
  reconstructed args:

...


That entry seems to have slain the compiler.  Shall I replay
your session? I can re-run each line except the last one.
[y/n]

see

https://groups.google.com/forum/?fromgroups#!topic/scala-internals/RA8xNVri60s%5B1-25%5D

@scabug
Copy link
Author

scabug commented Aug 14, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6236?orig=1
Reporter: DaveScala (davescala)
Affected Versions: 2.10.0-M6

@scabug
Copy link
Author

scabug commented Aug 14, 2012

@paulp said:
It's unrelated to the repl. Just nest like the repl does.

// a.scala
package p {
  object x {
    object x {
      @scala.annotation.static val foo: Int = 353
    }
  }
}
// b.scala - separately compiled
object Test {
  def main(args: Array[String]): Unit = {
    println(p.x.x.foo)
  }
}

@scabug
Copy link
Author

scabug commented Aug 14, 2012

DaveScala (davescala) said:
Thanks Paul, changed the title

@scabug
Copy link
Author

scabug commented Aug 16, 2012

@axel22 said:
Apparently, the first compilation creates a classfile for p.x.x which has a static field foo:

Compiled from "file_1.scala"
public class p.x$x extends java.lang.Object
  SourceFile: "file_1.scala"
  Scala: length = 0x
   
...

const #20 = Asciz	SourceFile;
const #21 = Asciz	Scala;

{
public static int foo;

...

}

During the second compilation, during icode, members of p.x.x are missing foo:

Scope{
  def <init>(): p.y$x;
  final def $asInstanceOf[T0 >: ? <: ?](): T0;
  final def $isInstanceOf[T0 >: ? <: ?](): Boolean;
  final def synchronized(x$1: Object): Object;
  final def ##(): Int;
  final def !=(x$1: Object): Boolean;
  final def ==(x$1: Object): Boolean;
  final def ne(x$1: Object): Boolean;
  final def eq(x$1: Object): Boolean;
  protected[package lang] def finalize(): Unit;
  final def wait(): Unit;
  final def wait(x$1: Long,x$2: Int): Unit;
  final def wait(x$1: Long): Unit;
  final def notifyAll(): Unit;
  final def notify(): Unit;
  def toString(): String;
  protected[package lang] def clone(): Object;
  def equals(x$1: Object): Boolean;
  def hashCode(): Int;
  final def getClass(): Class;
  def <init>(): Object
}

@scabug
Copy link
Author

scabug commented Aug 16, 2012

@paulp said:
When reading from bytecode, and when reading from java source, statics are mapped into the (possibly synthetic) companion object of the class being read. So although there is bytecode for p$x$x with a static field in it, the scala class p.x.x does not have it; the object p.x.x does.

If I change this:

val hostClass = qual.tpe.typeSymbol.orElse(sym.owner).companionClass

Not to call companionClass, then it finds the field foo and stops crashing. Of course then it fails at runtime with "java.lang.NoSuchFieldError: foo" because the confusion surrounding this is not so nicely localized.

@scabug
Copy link
Author

scabug commented Aug 16, 2012

@paulp said:
Ah, I see you made exactly that change in scala/scala#1138 .

@scabug
Copy link
Author

scabug commented Aug 17, 2012

@axel22 said:
Ah, of course - a static field won't be in the list of members of the class. Thanks for pointing this out.

I still call the companionClass in 1138, I just moved it to the next line.

@scabug
Copy link
Author

scabug commented Aug 17, 2012

@axel22 said (edited on Aug 17, 2012 8:16:31 AM UTC):
The symbol for {{foo}} in the companion object still has the static annotation during the second compilation. If the current run does not compile the companion object and the field is {{@static}}-annotated, then I can probably recreate the static field in the companion class.

@scabug
Copy link
Author

scabug commented Aug 17, 2012

@axel22 said:
scala/scala#1138

@scabug scabug closed this as completed Aug 17, 2012
@scabug scabug added this to the 2.10.0-M6 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants