@@ -114,7 +114,7 @@ class Objects(using Context @constructorOnly):
114
114
/**
115
115
* A reference caches the values for outers and immutable fields.
116
116
*/
117
- sealed abstract class Scope (using trace : Trace ):
117
+ sealed abstract class Scope (using trace : Trace ): // TODO: rename it to reflect that it is key to the heap
118
118
def isObjectRef : Boolean = this .isInstanceOf [ObjectRef ]
119
119
120
120
def getTrace : Trace = trace
@@ -293,7 +293,11 @@ class Objects(using Context @constructorOnly):
293
293
294
294
def toValueSet : ValueSet = ValueSet (scopes.asInstanceOf [Set [ValueElement ]])
295
295
296
- case class Package (packageModuleClass : ClassSymbol ) extends Value :
296
+ def lookupSymbol (sym : Symbol )(using Heap .MutableData ) = scopes.map(_.valValue(sym)).join
297
+
298
+ def outers (using Heap .MutableData ): ScopeSet = scopes.map(_.outer).join
299
+
300
+ case class Package (packageModuleClass : ClassSymbol ) extends Value : // TODO: try to remove packages
297
301
def show (using Context ): String = " Package(" + packageModuleClass.show + " )"
298
302
299
303
object Package :
@@ -448,7 +452,7 @@ class Objects(using Context @constructorOnly):
448
452
val outerThis = resolveThisRecur(targetClass, resultSet)
449
453
Some ((outerThis, resultSet))
450
454
else
451
- val outerScopes = scopeSet.scopes.map(_.outer).join
455
+ val outerScopes = scopeSet.outers
452
456
resolveEnvRecur(target, outerScopes, bySymbol)
453
457
454
458
@@ -1184,7 +1188,7 @@ class Objects(using Context @constructorOnly):
1184
1188
// Assume forward reference check is doing a good job
1185
1189
val scopesOwnedByOthers = scopeSet.scopes.filter(_.owner != State .currentObject)
1186
1190
if scopesOwnedByOthers.isEmpty then
1187
- scopeSet.scopes.map(_.varValue( sym)).join
1191
+ scopeSet.lookupSymbol( sym)
1188
1192
else
1189
1193
errorReadOtherStaticObject(State .currentObject, scopesOwnedByOthers.head)
1190
1194
Bottom
@@ -1195,7 +1199,7 @@ class Objects(using Context @constructorOnly):
1195
1199
eval(rhs, thisV, sym.enclosingClass.asClass, cacheResult = true )
1196
1200
else
1197
1201
// Assume forward reference check is doing a good job
1198
- val value = scopeSet.scopes.map(_.varValue( sym)).join
1202
+ val value = scopeSet.lookupSymbol( sym)
1199
1203
if isByNameParam(sym) then
1200
1204
evalByNameParam(value)
1201
1205
else
@@ -1835,7 +1839,7 @@ class Objects(using Context @constructorOnly):
1835
1839
}
1836
1840
1837
1841
// parents
1838
- def initParent (parent : Tree , tasks : Tasks ) =
1842
+ def initParent (parent : Tree , tasks : Tasks ) = // TODO: store the parent objects and resolve `p.this` for parent classes `p`
1839
1843
parent match
1840
1844
case tree @ Block (stats, NewExpr (tref, New (tpt), ctor, argss)) => // can happen
1841
1845
evalExprs(stats, thisV, klass)
@@ -1933,9 +1937,9 @@ class Objects(using Context @constructorOnly):
1933
1937
if klass == target then
1934
1938
scopeSet.toValueSet
1935
1939
else
1936
- resolveThisRecur(target, scopeSet.scopes.map(_.outer).join )
1940
+ resolveThisRecur(target, scopeSet.outers )
1937
1941
else
1938
- resolveThisRecur(target, scopeSet.scopes.map(_.outer).join )
1942
+ resolveThisRecur(target, scopeSet.outers )
1939
1943
1940
1944
/** Resolve C.this that appear in `D.this`
1941
1945
*
0 commit comments