@@ -145,7 +145,9 @@ class Semantic {
145
145
* Invariant: fields are immutable and only set once from `init`
146
146
*/
147
147
def updateField (field : Symbol , value : Value ): Contextual [Unit ] =
148
- heap(ref).fields(field) = value
148
+ val fields = heap(ref).fields
149
+ assert(! fields.contains(field), field.show + " already init, new = " + value + " , ref =" + ref)
150
+ fields(field) = value
149
151
150
152
/** Update the immediate outer of the given `klass` of the abstract object
151
153
*
@@ -400,7 +402,8 @@ class Semantic {
400
402
if target.isPrimaryConstructor then
401
403
given Env = env2
402
404
val tpl = cls.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
403
- eval(tpl, addr, cls, cacheResult = true )
405
+ val res = eval(tpl, addr, cls, cacheResult = true )
406
+ Result (addr, res.errors)
404
407
else if target.isConstructor then
405
408
given Env = env2
406
409
eval(ddef.rhs, addr, cls, cacheResult = true )
@@ -441,7 +444,21 @@ class Semantic {
441
444
val trace1 = trace.add(source)
442
445
value match {
443
446
case Hot =>
444
- Result (Hot , Errors .empty)
447
+ val buffer = new mutable.ArrayBuffer [Error ]
448
+ val args2 = args.map { arg =>
449
+ val errors = arg.promote(" May only use initialized value as arguments" , arg.source)
450
+ buffer ++= errors
451
+ if errors.isEmpty then Hot
452
+ else arg.widen
453
+ }
454
+ if buffer.isEmpty then Result (Hot , Errors .empty)
455
+ else
456
+ val value = Warm (klass, Hot , ctor, args2)
457
+ if ! heap.contains(value) then
458
+ val obj = Objekt (klass, fields = mutable.Map .empty, outers = mutable.Map (klass -> Hot ))
459
+ heap.update(value, obj)
460
+ val res = value.call(ctor, args, superType = NoType , source)
461
+ Result (res.value, res.errors)
445
462
446
463
case Cold =>
447
464
val error = CallCold (ctor, source, trace1.toVector)
@@ -990,7 +1007,7 @@ class Semantic {
990
1007
991
1008
// class body
992
1009
tpl.body.foreach {
993
- case vdef : ValDef if ! vdef.symbol.is(Flags .Lazy ) =>
1010
+ case vdef : ValDef if ! vdef.symbol.is(Flags .Lazy ) && ! vdef.rhs.isEmpty =>
994
1011
given Env = Env .empty
995
1012
val res = eval(vdef.rhs, thisV, klass, cacheResult = true )
996
1013
errorBuffer ++= res.errors
0 commit comments