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

Scala 2.13.1 regression: Crash on lazy vals initialised from class parameters #11855

Closed
TJC opened this issue Jan 20, 2020 · 5 comments
Closed

Comments

@TJC
Copy link

TJC commented Jan 20, 2020

Description

Regression when upgrading from Scala 2.12.10 to 2.13.1:
'lazy vals' cause java.lang.IllegalAccessError if they are initialised with a class parameter.

class LazyConstructors(thingCons: (String) => MyThing) {
  lazy val thing: MyThing = thingCons("foo")
  def callMe = thing.toString
}
java.lang.IllegalAccessError: Update to non-static final field example.LazyConstructors.thingCons attempted from a different method (thing$lzycompute) than the initializer method <init> .

Workaround

In the above code, making this change results in the code no longer crashing -- just defining the class parameter as a val

class LazyConstructors(val thingCons: (String) => MyThing)

Environment:

  • Scala 2.13.1
  • OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)
  • sbt 1.3.7

Runnable code demonstrating issue

https://github.com/TJC/scala-2.13-lazy-val-issue

Check out the repo, ensure you have JDK 11, and then run sbt test

@TJC
Copy link
Author

TJC commented Jan 20, 2020

Looks like this is a duplicate of #11781 ?

@TJC TJC changed the title Scala 2.13 regression: Crash on lazy vals initialised from class parameters Scala 2.13.1 regression: Crash on lazy vals initialised from class parameters Jan 20, 2020
@som-snytt
Copy link

som-snytt commented Jan 20, 2020

Did that fix not merge forward?

Maybe scala/scala#8648

@som-snytt
Copy link

The fix just missed the previous forward merge by a couple of days.

@TJC
Copy link
Author

TJC commented Jan 22, 2020

Ah, oh no!
But it'll definitely be coming along in 2.13.2 then? That's good to know.

@dwijnand
Copy link
Member

Yep.

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

3 participants