We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
The Mixin phase currently emits initializer calls for lazy vals in mixed in traits, even if those fields were overridden:
Mixin
trait A { lazy val x = { println("super[A].x()"); 123 } } class B extends A { override lazy val x = 456 } object HelloWorld { def main(args: Array[String]): Unit = { new B() } }
results in output
super[A].x()
My ad-hoc fix is to check for override during the generation of those initializers, though I'm not sure that's the correct way to handle it:
override
diff --git a/compiler/src/dotty/tools/dotc/transform/Mixin.scala b/compiler/src/dotty/tools/dotc/transform/Mixin.scala index 437a8a45af3..d10ccebb370 100644 --- a/compiler/src/dotty/tools/dotc/transform/Mixin.scala +++ b/compiler/src/dotty/tools/dotc/transform/Mixin.scala @@ -213,8 +213,10 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase => cls.pos) EmptyTree } + def needsInit(getter: Symbol) = + getter.isGetter && !was(getter, Deferred) && !cls.info.decl(getter.name).symbol.is(Override) - for (getter <- mixin.info.decls.toList if getter.isGetter && !was(getter, Deferred)) yield { + for (getter <- mixin.info.decls.toList if needsInit(getter)) yield { val isScala2x = mixin.is(Scala2x) def default = Underscore(getter.info.resultType) def initial = transformFollowing(superRef(initializer(getter)).appliedToNone)
The text was updated successfully, but these errors were encountered:
12ead8d
Merge pull request #4636 from dotty-staging/fix-#4559
69b539c
Fix #4559: Don't force initializers of lazy mixin fields
odersky
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
The
Mixin
phase currently emits initializer calls for lazy vals in mixed in traits, even if those fields were overridden:results in output
My ad-hoc fix is to check for
override
during the generation of those initializers, though I'm not sure that's the correct way to handle it:The text was updated successfully, but these errors were encountered: