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 java.lang.IllegalAccessError thrown when accessing symbols in traits with self type #8933

Closed
scabug opened this issue Oct 22, 2014 · 3 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Oct 22, 2014

The following code shows how the error can be generated. The trait needs to be put in a separate file:

File: MixinWithSymbol.scala

trait MixinWithSymbol {
  self: MotherClass =>
  def symbolFromTrait: Symbol = 'traitSymbol
}

File: SymbolApp.scala

class MotherClass extends MixinWithSymbol {
  val classSymbol = 'classSymbol
}

object SymbolApp extends App {
  val symbol = (new MotherClass).symbolFromTrait
  println(symbol)  // Error!
}

Running this code after a clean build in sbt generates the following error:

java.lang.IllegalAccessError: tried to access field MotherClass.symbol$1 from class MixinWithSymbol$class
        at MixinWithSymbol$class.symbolFromTrait(MixinWithSymbol.scala:3)
        at MotherClass.symbolFromTrait(SymbolApp.scala:1)
        at SymbolApp$.delayedEndpoint$SymbolApp$1(SymbolApp.scala:6)
        at SymbolApp$delayedInit$body.apply(SymbolApp.scala:5)
        at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
        at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
        at scala.App$$anonfun$main$1.apply(App.scala:76)
        at scala.App$$anonfun$main$1.apply(App.scala:76)
        at scala.collection.immutable.List.foreach(List.scala:381)
        at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
        at scala.App$class.main(App.scala:76)
        at SymbolApp$.main(SymbolApp.scala:5)
        at SymbolApp.main(SymbolApp.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)

Other observations:

  • By doing an incremental build, e.g. a small change in the file containing the trait, the error disappears at the next run. After a clean compile, the error turns up again.

  • Removing the self type in the trait makes the code work

  • Adding an object with a symbol definition in the top of one of the files makes the code work

  • Removing the symbol definition from MotherClass makes the code work

@scabug
Copy link
Author

scabug commented Oct 22, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8933?orig=1
Reporter: B. Tommy Jensen (tommy-at-grindvoll.com)
Affected Versions: 2.11.2
Attachments:

@scabug
Copy link
Author

scabug commented Oct 23, 2014

@retronym said:
Thanks for the minimization.

I confirm that I can reproduce this with this test case: https://github.com/retronym/scala/tree/ticket/8933

Regressed in scala/scala#3149 (although that really uncovered a latent bug)

@scabug
Copy link
Author

scabug commented Nov 6, 2014

@retronym said:
scala/scala#4095

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