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

"Unexpected tree in genLoad" compiler crash when invoking super on java method of class with package access #5650

Closed
scabug opened this issue Apr 7, 2012 · 4 comments

Comments

@scabug
Copy link

scabug commented Apr 7, 2012

When trying to invoke a super method from java base class I got a very strange error:

Unexpected tree in genLoad: Worker.super/class scala.reflect.api.Trees$Super at: source-..\Worker.scala,line-9,offset=130

while compiling:  Worker.scala
current phase:  icode
library version:  version 2.10.0-20120406-151649-1a6408c429
compiler version:  version 2.10.0-20120406-151649-1a6408c429
uncaught exception during compilation: scala.reflect.internal.FatalError
 scala.reflect.internal.Fatal
Unexpected tree in genLoad: Worker.super/class scala.reflect.api.Trees$Super at: source-...\Worker.scala,line-9,offset=130
at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:40)
at scala.tools.nsc.Global.abort(Global.scala:191)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:1105)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.genLoadQualifier(GenICode.scala:1150)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:721)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.scala$tools$nsc$backend$icode$GenICode$ICodePhase$$genLoad(GenICode.scala:901)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:115)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase$$anonfun$gen$1.apply(GenICode.scala:71)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:77)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:71)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:140)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:90)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:81)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:67)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:63)
at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:421)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:387)
at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:381)
at scala.collection.Iterator$class.foreach(Iterator.scala:697)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1124)
at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:381)
at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:56)
at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1303)
at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1276)
at scala.tools.nsc.Global$Run.compileSources(Global.scala:1270)
at scala.tools.nsc.Global$Run.compile(Global.scala:1403)
at scala.tools.nsc.Driver.doCompile(Driver.scala:31)
at scala.tools.nsc.Main$.doCompile(Main.scala:81)
at scala.tools.nsc.Driver.process(Driver.scala:52)
at scala.tools.nsc.Driver.main(Driver.scala:65)
at scala.tools.nsc.Main.main(Main.scala)

Finally I was able to reproduce this case. The problem arise when you override a method in base class hierarchy
where class which defines a given method has a package access modifier.

Here a example:

//base abstract public class

package com.test;

public abstract class Base {

}

//class in the middle of the inheritance chain that has a package wide access

package com.test;

class Middle extends Base {
    public void doSomething() {
        System.out.println("You just called a base class!");
    }
}

//a public class that inherits from a previous class

package com.test;

public class Top extends Middle {

}

//a scala class that inherits from a public class but overrides a method defined in class with default access

import com.test.Top

class Worker extends Top {

  override def doSomething() {
    super.doSomething()
  }

}

Of course this case should be rare in practice but at least the compiler should not crash on this.

@scabug
Copy link
Author

scabug commented Apr 7, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5650?orig=1
Reporter: Aliaksandr Zhuhrou (zhygr)
Affected Versions: 2.10.0
Duplicates #4626

@scabug
Copy link
Author

scabug commented Apr 7, 2012

Aliaksandr Zhuhrou (zhygr) said:
Also the related problem that you may actually override a inaccessible method and in you don't call super the compiler say you nothing.
But in the end you get an IllegalAccessException.
Example

import com.test.Top

class Worker extends Top {

override def doSomething() { System.out.println("Hm. It works.") }

}

In this case my intuition says that compiler should also give you a meanfull error.

@scabug
Copy link
Author

scabug commented May 4, 2012

@magarciaEPFL said:
Workaround (and probably the most sensible design, anyway)

package com.test

class Worker extends Top {
  . . . 

@scabug
Copy link
Author

scabug commented May 4, 2012

@paulp said:
This is a duplicate of #4626.

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