Skip to content

Illegal access error when constructor parameter has same name and more specific type #7926

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

Closed
travisbrown opened this issue Jan 8, 2020 · 0 comments
Assignees

Comments

@travisbrown
Copy link
Contributor

minimized code

trait Foo {
  def parent: Option[Foo]
  def getParent: Option[Foo] = parent
}

class Bar(val parent: Option[Foo]) extends Foo
class Qux(parent: Option[Qux]) extends Bar(parent)

object Qux {
  val qux: Qux = new Qux(None)

  def main(args: Array[String]): Unit = println(qux.getParent)
}
This code compiles, but crashes at runtime.
Exception in thread "main" java.lang.IllegalAccessError: Qux.parent()Lscala/Option;
        at Foo.getParent(Foo.scala:3)
        at Bar.getParent(Foo.scala:6)
        at Qux$.main(Foo.scala:12)
        at Qux.main(Foo.scala)

expectation

It should print None, like Scala 2 does. Note that changing Qux's constructor parameter name to something other than parent fixes the issue.

@odersky odersky self-assigned this Jan 13, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 3, 2020
 - Move main optimization after unpickling, so that changes
   to parameters in superclasses do not break Tasty compatibility.
 - Replace internal Alias annotation by SuperParamAlias flag
 - Don't generate illegal private overrides
 - Make the transformation more robust under separate compilation
   and wrt compilation order
@smarter smarter closed this as completed in b8b32be Mar 5, 2020
smarter added a commit that referenced this issue Mar 5, 2020
Fix #7926: Redo parameter aliasing optimization
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