@@ -186,18 +186,29 @@ class Objects(using Context @constructorOnly):
186186
187187 def outerValue (sym : Symbol )(using Heap .MutableData ): Value = Heap .readOuter(this , sym)
188188
189+ def hasOuter (classSymbol : Symbol )(using Heap .MutableData ): Boolean = Heap .hasOuter(this , classSymbol)
190+
189191 def outer (using Heap .MutableData ): Value = this .outerValue(klass)
190192
191193 def outerEnv (using Heap .MutableData ): Env .EnvSet = Heap .readOuterEnv(this )
192194 end Ref
193195
194- /** A reference to a static object */
196+ /** A reference to a static object
197+ *
198+ * Invariant: The reference itself should not contain any state
199+ *
200+ * Rationale: There can be multiple references to the same object. They must
201+ * share the same state.
202+ */
195203 case class ObjectRef private (klass : ClassSymbol )(using Trace ) extends Ref :
196- var afterSuperCall = false
197-
198- def isAfterSuperCall = afterSuperCall
204+ /** Use the special outer to denote whether the super constructor of the
205+ * object has been called or not.
206+ */
207+ def isAfterSuperCall (using Heap .MutableData ) =
208+ this .hasOuter(klass.sourceModule)
199209
200- def setAfterSuperCall (): Unit = afterSuperCall = true
210+ def setAfterSuperCall ()(using Heap .MutableData ): Unit =
211+ this .initOuter(klass.sourceModule, Bottom )
201212
202213 def owner = klass
203214
@@ -707,6 +718,9 @@ class Objects(using Context @constructorOnly):
707718 def readOuter (ref : Ref , parent : Symbol )(using mutable : MutableData ): Value =
708719 mutable.heap(ref).outersMap(parent)
709720
721+ def hasOuter (ref : Ref , parent : Symbol )(using mutable : MutableData ): Boolean =
722+ mutable.heap(ref).outersMap.contains(parent)
723+
710724 def readOuterEnv (ref : Ref )(using mutable : MutableData ): Env .EnvSet =
711725 mutable.heap(ref).outerEnvs
712726
@@ -1701,7 +1715,7 @@ class Objects(using Context @constructorOnly):
17011715 val args = evalArgs(elems.map(Arg .apply), thisV, klass)
17021716 val arr = ArrayRef (State .currentObject, summon[Regions .Data ])
17031717 arr.writeElement(args.map(_.value).join)
1704- call(ObjectRef (module), meth, List (ArgInfo (arr, summon[Trace ], EmptyTree )), module.typeRef, NoType )
1718+ call(accessObject (module), meth, List (ArgInfo (arr, summon[Trace ], EmptyTree )), module.typeRef, NoType )
17051719
17061720 case Inlined (call, bindings, expansion) =>
17071721 evalExprs(bindings, thisV, klass)
0 commit comments