@@ -444,9 +444,9 @@ class Objects(using Context @constructorOnly):
444
444
* Due to widening, the corresponding environment might not exist. As a result reading the local
445
445
* variable will return `Cold` and it's forbidden to write to the local variable.
446
446
*
447
- * @param target The symbol to search for.
448
- * @param thisV The value for `this` of the enclosing class where the local variable is referenced.
449
- * @param env The local environment where the local variable is referenced.
447
+ * @param target The symbol to search for.
448
+ * @param thisV The value for `this` of the enclosing class where the local variable is referenced.
449
+ * @param env The local environment where the local variable is referenced.
450
450
*
451
451
* @return the environment that owns the `target` and value for `this` owned by the given method.
452
452
*/
@@ -470,31 +470,33 @@ class Objects(using Context @constructorOnly):
470
470
}
471
471
472
472
/**
473
- * Resolve the environment owned by the given method.
473
+ * Resolve the environment owned by the given method `enclosing` .
474
474
*
475
475
* The method could be located in outer scope with intermixed classes between its definition
476
476
* site and usage site.
477
477
*
478
478
* Due to widening, the corresponding environment might not exist. As a result reading the local
479
479
* variable will return `Cold` and it's forbidden to write to the local variable.
480
480
*
481
- * @param meth The method which owns the environment
482
- * @param thisV The value for `this` of the enclosing class where the local variable is referenced.
483
- * @param env The local environment where the local variable is referenced.
481
+ * @param enclosing The method which owns the environment. This method is called to look up the environment
482
+ * owned by the enclosing method of some symbol.
483
+ * @param thisV The value for `this` of the enclosing class where the local variable is referenced.
484
+ * @param env The local environment where the local variable is referenced.
484
485
*
485
486
* @return the environment and value for `this` owned by the given method.
486
487
*/
487
- def resolveEnvByOwner (meth : Symbol , thisV : ThisValue , env : Data )(using Context ): Option [(ThisValue , Data )] = log(" Resolving env by owner for " + meth.show + " , this = " + thisV.show + " , env = " + env.show, printer) {
488
+ def resolveEnvByOwner (enclosing : Symbol , thisV : ThisValue , env : Data )(using Context ): Option [(ThisValue , Data )] = log(" Resolving env by owner for " + enclosing.show + " , this = " + thisV.show + " , env = " + env.show, printer) {
489
+ assert(enclosing.is(Flags .Method ), " Only method symbols allows, got " + enclosing.show)
488
490
env match
489
491
case localEnv : LocalEnv =>
490
- if localEnv.meth == meth then Some (thisV -> env)
491
- else resolveEnvByOwner(meth , thisV, localEnv.outer)
492
+ if localEnv.meth == enclosing then Some (thisV -> env)
493
+ else resolveEnvByOwner(enclosing , thisV, localEnv.outer)
492
494
case NoEnv =>
493
495
thisV match
494
496
case ref : OfClass =>
495
497
ref.outer match
496
498
case outer : ThisValue =>
497
- resolveEnvByOwner(meth , outer, ref.env)
499
+ resolveEnvByOwner(enclosing , outer, ref.env)
498
500
case _ =>
499
501
// TODO: properly handle the case where ref.outer is ValueSet
500
502
None
0 commit comments