File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -252,9 +252,17 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
252252 case _ => superCalls
253253 }
254254
255+ // Lazy Vals may decide to create an eager val instead of a lazy val
256+ // this val should be assigned before constructor body code starts running
257+
258+ val (lazyAssignments, stats) = followConstrStats.partition {
259+ case Assign (l, r) if l.symbol.name.is(NameKinds .LazyLocalName ) => true
260+ case _ => false
261+ }
262+
255263 cpy.Template (tree)(
256264 constr = cpy.DefDef (constr)(
257- rhs = Block (copyParams ::: mappedSuperCalls ::: followConstrStats , unitLiteral)),
265+ rhs = Block (copyParams ::: mappedSuperCalls ::: lazyAssignments ::: stats , unitLiteral)),
258266 body = clsStats.toList)
259267 }
260268}
Original file line number Diff line number Diff line change 1+ class Bees {
2+ def f : PartialFunction [Bee , Unit ] = { case Bee (_) => " " }
3+
4+ f(new Bee (" buzz" ))
5+
6+ case class Bee (value : String )
7+ // object Bee // With this it works
8+ }
9+
10+ object Test {
11+ def main (args : Array [String ]): Unit = {
12+ new Bees
13+ }
14+ }
You can’t perform that action at this time.
0 commit comments