@@ -97,7 +97,7 @@ class Objects(using Context @constructorOnly):
97
97
* RefSet ::= Set(ref) // set of refs
98
98
* Bottom ::= RefSet(Empty) // unreachable code
99
99
* ThisValue ::= Ref | RefSet // possible values for 'this'
100
- * EnvRef(tree, ownerObject) // represents environments for methodsor functions
100
+ * EnvRef(tree, ownerObject) // represents environments for evaluating methods, functions, or lazy/by-name values
101
101
* EnvSet ::= Set(EnvRef)
102
102
* InstanceBody ::= (valsMap: Map[Symbol, Value],
103
103
outersMap: Map[ClassSymbol, Value],
@@ -405,11 +405,13 @@ class Objects(using Context @constructorOnly):
405
405
406
406
/** Environment for parameters */
407
407
object Env :
408
- /** Local environments can be deeply nested, therefore we need `outer`.
409
- *
410
- * For local variables in rhs of class field definitions, the `meth` is the primary constructor.
411
- */
408
+ /** Represents environments for evaluating methods, functions, or lazy/by-name values */
412
409
case class EnvRef (tree : Tree , owner : ClassSymbol )(using Trace ) extends Scope :
410
+ override def equals (that : Any ): Boolean =
411
+ that.isInstanceOf [EnvRef ] &&
412
+ (that.asInstanceOf [EnvRef ].tree eq tree) &&
413
+ (that.asInstanceOf [EnvRef ].owner == owner)
414
+
413
415
def show (using Context ) =
414
416
" tree: " + tree.show + " \n " +
415
417
" owner: " + owner.show
@@ -478,7 +480,7 @@ class Objects(using Context @constructorOnly):
478
480
val params = ddef.termParamss.flatten.map(_.symbol)
479
481
assert(args.size == params.size, " arguments = " + args.size + " , params = " + params.size)
480
482
// assert(ddef.symbol.owner.is(Method) ^ (outerEnv == NoEnv), "ddef.owner = " + ddef.symbol.owner.show + ", outerEnv = " + outerEnv + ", " + ddef.source)
481
- _of(params.zip(args).toMap, ddef, thisV, outerEnv)
483
+ _of(params.zip(args).toMap, ddef.rhs , thisV, outerEnv)
482
484
483
485
484
486
/**
@@ -692,6 +694,11 @@ class Objects(using Context @constructorOnly):
692
694
def setHeap (newHeap : Data )(using mutable : MutableData ): Unit = mutable.heap = newHeap
693
695
end Heap
694
696
697
+ /**
698
+ * Local environments can be deeply nested, therefore we need `outerEnvs`, which stores the immediate outer environment.
699
+ * If the immediate enclosing scope of an environment is a template, then `outerEnvs` is empty in EnvMap.
700
+ * We can restore outerEnvs of `this` in the heap.
701
+ */
695
702
object EnvMap :
696
703
private case class EnvBody (
697
704
valsMap : Map [Symbol , Value ],
0 commit comments