Skip to content

Commit 69b539c

Browse files
authored
Merge pull request #4636 from dotty-staging/fix-#4559
Fix #4559: Don't force initializers of lazy mixin fields
2 parents 1dce677 + 04f5bf3 commit 69b539c

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Mixin.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class Mixin extends MiniPhase with SymTransformer { thisPhase =>
242242
// transformFollowing call is needed to make memoize & lazy vals run
243243
transformFollowing(DefDef(implementation(getter.asTerm), rhs))
244244
}
245-
else if (isScala2x || was(getter, ParamAccessor)) EmptyTree
245+
else if (isScala2x || was(getter, ParamAccessor | Lazy)) EmptyTree
246246
else initial
247247
}
248248
}

tests/run/i4559.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
super[A] init
2+
x()

tests/run/i4559.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
trait A {
2+
println(s"super[A] init")
3+
lazy val x = { println("super[A].x()"); 123 }
4+
}
5+
6+
class B extends A {
7+
override lazy val x = { println("x()"); 456 }
8+
}
9+
10+
object Test { def main(args: Array[String]): Unit = { new B().x } }

0 commit comments

Comments
 (0)