@@ -257,6 +257,18 @@ class Semantic {
257257 }
258258 end extension
259259
260+ extension (addr : Addr )
261+ def updateOuter (klass : ClassSymbol , value : Value ): Unit =
262+ val obj = heap(addr)
263+ val obj2 = obj.copy(outers = obj.outers.updated(klass, value))
264+ heap(addr) = obj2
265+
266+ def updateField (field : Symbol , value : Value ): Unit =
267+ val obj = heap(addr)
268+ val obj2 = obj.copy(fields = obj.fields.updated(field, value))
269+ heap(addr) = obj2
270+ end extension
271+
260272
261273// ----- Semantic definition --------------------------------
262274
@@ -526,9 +538,7 @@ class Semantic {
526538 val cls = tref.classSymbol.asClass
527539 val res = outerValue(tref, thisV, klass, source)
528540 errorBuffer ++= res.errors
529- val obj = heap(thisV)
530- val obj2 = obj.copy(outers = obj.outers.updated(cls, res.value))
531- heap(thisV) = obj2
541+ thisV.updateOuter(cls, res.value)
532542
533543 // follow constructor
534544 val res2 = thisV.call(ctor, superType = NoType , source)
@@ -563,9 +573,7 @@ class Semantic {
563573 case vdef : ValDef =>
564574 val res = eval(vdef.rhs, thisV, klass)
565575 errorBuffer ++ res.errors
566- val obj = heap(thisV)
567- val obj2 = obj.copy(fields = obj.fields.updated(vdef.symbol, res.value))
568- heap(thisV) = obj2
576+ thisV.updateField(vdef.symbol, res.value)
569577
570578 case _ : MemberDef =>
571579
0 commit comments