@@ -569,7 +569,26 @@ object Semantic {
569569 report.error(" unexpected constructor call, meth = " + ctor + " , value = " + value, source)
570570 Result (Hot , Nil )
571571
572- case ref : Ref =>
572+ case ref : Warm =>
573+ val trace1 = trace.add(source)
574+ if ctor.hasSource then
575+ given Trace = trace1
576+ val cls = ctor.owner.enclosingClass.asClass
577+ val ddef = ctor.defTree.asInstanceOf [DefDef ]
578+ given Env = Env (ddef, args.map(_.value).widenArgs)
579+ if ctor.isPrimaryConstructor then
580+ val tpl = cls.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
581+ init(tpl, ref, cls)
582+ else
583+ val initCall = ddef.rhs match
584+ case Block (call :: _, _) => call
585+ case call => call
586+ eval(initCall, ref, cls)
587+ end if
588+ else
589+ Result (Hot , Nil )
590+
591+ case ref : ThisRef =>
573592 val trace1 = trace.add(source)
574593 if ctor.hasSource then
575594 given Trace = trace1
@@ -871,6 +890,7 @@ object Semantic {
871890 */
872891 private def doTask (task : Task )(using State , Context ): Result = log(" checking " + task) {
873892 val thisRef = task.value
893+ thisRef.ensureObjectExists()
874894 val tpl = thisRef.klass.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
875895
876896 val paramValues = tpl.constr.termParamss.flatten.map(param => param.symbol -> Hot ).toMap
@@ -1260,7 +1280,7 @@ object Semantic {
12601280 thisV.updateOuter(cls, res.value)
12611281
12621282 // follow constructor
1263- if cls.hasSource then
1283+ if cls.hasSource && ! thisV.isWarm then
12641284 tasks.append { () =>
12651285 printer.println(" init super class " + cls.show)
12661286 val res2 = thisV.callConstructor(ctor, args, source)
@@ -1331,7 +1351,7 @@ object Semantic {
13311351 var fieldsChanged = true
13321352
13331353 // class body
1334- tpl.body.foreach {
1354+ if ( ! thisV.isWarm) tpl.body.foreach {
13351355 case vdef : ValDef if ! vdef.symbol.is(Flags .Lazy ) && ! vdef.rhs.isEmpty =>
13361356 given Env = Env .empty
13371357 val res = eval(vdef.rhs, thisV, klass)
@@ -1342,11 +1362,8 @@ object Semantic {
13421362 case _ : MemberDef =>
13431363
13441364 case tree =>
1345- thisV match
1346- case thisRef : ThisRef =>
1347- if fieldsChanged then thisRef.tryPromoteCurrentObject
1348- fieldsChanged = false
1349- case _ =>
1365+ if fieldsChanged then thisV.asInstanceOf [ThisRef ].tryPromoteCurrentObject
1366+ fieldsChanged = false
13501367
13511368 given Env = Env .empty
13521369 errorBuffer ++= eval(tree, thisV, klass).errors
0 commit comments