Skip to content

[REVISIT] Avoid compiler crash when overriding lazy val with abstract def [ci: last-only] #10505

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
wants to merge 4 commits into from

Conversation

som-snytt
Copy link
Contributor

@scala-jenkins scala-jenkins added this to the 2.13.13 milestone Aug 23, 2023
// if current class is a trait, add an abstract method for accessor `sym`
// ditto for a super accessor (will get an RHS in completeSuperAccessor)
if (clazz.isTrait || sym.isSuperAccessor) addDefDef(sym)
// implement methods mixed in from a supertrait (the symbols were created by mixinTraitMembers)
else if (sym.hasFlag(ACCESSOR) && !sym.hasFlag(DEFERRED)) {
assert(sym hasFlag (PARAMACCESSOR), s"mixed in $sym from $clazz is not param?!?")
else if (sym.hasFlag(ACCESSOR) && sym.hasNoFlags(DEFERRED|LAZY)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't skip only the assertion, but also addDedDef. Not sure if that's correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran out of midnight before I learned what is going on. Adriaan left comments about lazy vals from fields work, which are on my reading list. Mixin used to do work for lazy vals before then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plenty of time to add tests before 2.13.13.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

berühmte letzte Worte.

@som-snytt som-snytt force-pushed the issue/10223-override-crash branch 2 times, most recently from af73368 to b844a1a Compare August 24, 2023 08:11
@som-snytt som-snytt changed the title Maybe don't assert [ci: last-only] Let lazy dogs lie in mixin [ci: last-only] Aug 24, 2023
@som-snytt som-snytt marked this pull request as ready for review August 24, 2023 08:13
@som-snytt som-snytt force-pushed the issue/10223-override-crash branch from b844a1a to e1cce93 Compare September 1, 2023 16:01
@SethTisue
Copy link
Member

@lrytz re-review?

@SethTisue SethTisue changed the title Let lazy dogs lie in mixin [ci: last-only] Avoid compiler crash when overriding lazy val with abstract def [ci: last-only] Sep 19, 2023
@lrytz
Copy link
Member

lrytz commented Sep 21, 2023

This is a difficult area; I don't have a good model present about fields and mixin, and didn't dive in their implementaiton.

Observationtion from compiling an example with -Vprint

package p
trait T { lazy val x: String = { System.out.println("init"); "hello, world" } }
abstract class A extends T { override def x: Any }
abstract class B extends T
  • A is left untouched in fields
  • B gets the lazy val implementation (field, x$lzycompute, bitmap, getter) in fields
  • A gets a bridge in erasure
  • With the patch of this PR, A gets a forwarder in mixin <stable> <accessor> lazy <sub_synth> def x(): String = A.super.x();

In jshell

jshell> var a = new p.A(){}
a ==> $0@20e2cbe0

jshell> a.x()
init
$2 ==> "hello, world"

jshell> a.x()
init
$3 ==> "hello, world"

So not a lazy val.

@som-snytt som-snytt marked this pull request as draft September 21, 2023 14:49
@som-snytt
Copy link
Contributor Author

thanks @lrytz I'll dive back in, as I promised a month ago. 2.13.13 seemed so far away, but Friday 13th is just around the corner.

@som-snytt som-snytt self-assigned this Sep 21, 2023
@lrytz lrytz modified the milestones: 2.13.13, 2.13.14 Nov 28, 2023
@SethTisue SethTisue modified the milestones: 2.13.14, 2.13.15 Mar 13, 2024
@som-snytt som-snytt closed this Mar 20, 2024
@SethTisue SethTisue removed this from the 2.13.15 milestone Mar 21, 2024
@som-snytt som-snytt changed the title Avoid compiler crash when overriding lazy val with abstract def [ci: last-only] [REVISIT] Avoid compiler crash when overriding lazy val with abstract def [ci: last-only] Jan 27, 2025
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

Successfully merging this pull request may close these issues.

Compiler crash with AssertionError "mixed in lazy value .. from class .. is not param?!"
4 participants