Skip to content

Commit 480a6d5

Browse files
author
EnzeXing
committed
Address comments
1 parent c22d011 commit 480a6d5

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ class Objects(using Context @constructorOnly):
9797
* RefSet ::= Set(ref) // set of refs
9898
* Bottom ::= RefSet(Empty) // unreachable code
9999
* ThisValue ::= Ref | RefSet // possible values for 'this'
100-
* EnvRef(tree, ownerObject) // represents environments for methods or functions
100+
* EnvRef(tree, ownerObject) // represents environments for evaluating methods, functions, or lazy/by-name values
101101
* EnvSet ::= Set(EnvRef)
102102
* InstanceBody ::= (valsMap: Map[Symbol, Value],
103103
outersMap: Map[ClassSymbol, Value],
@@ -405,11 +405,13 @@ class Objects(using Context @constructorOnly):
405405

406406
/** Environment for parameters */
407407
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 */
412409
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+
413415
def show(using Context) =
414416
"tree: " + tree.show + "\n" +
415417
"owner: " + owner.show
@@ -478,7 +480,7 @@ class Objects(using Context @constructorOnly):
478480
val params = ddef.termParamss.flatten.map(_.symbol)
479481
assert(args.size == params.size, "arguments = " + args.size + ", params = " + params.size)
480482
// 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)
482484

483485

484486
/**
@@ -692,6 +694,11 @@ class Objects(using Context @constructorOnly):
692694
def setHeap(newHeap: Data)(using mutable: MutableData): Unit = mutable.heap = newHeap
693695
end Heap
694696

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+
*/
695702
object EnvMap:
696703
private case class EnvBody(
697704
valsMap: Map[Symbol, Value],

0 commit comments

Comments
 (0)