@@ -444,9 +444,9 @@ class Objects(using Context @constructorOnly):
444444 * Due to widening, the corresponding environment might not exist. As a result reading the local
445445 * variable will return `Cold` and it's forbidden to write to the local variable.
446446 *
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.
450450 *
451451 * @return the environment that owns the `target` and value for `this` owned by the given method.
452452 */
@@ -470,31 +470,33 @@ class Objects(using Context @constructorOnly):
470470 }
471471
472472 /**
473- * Resolve the environment owned by the given method.
473+ * Resolve the environment owned by the given method `enclosing` .
474474 *
475475 * The method could be located in outer scope with intermixed classes between its definition
476476 * site and usage site.
477477 *
478478 * Due to widening, the corresponding environment might not exist. As a result reading the local
479479 * variable will return `Cold` and it's forbidden to write to the local variable.
480480 *
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.
484485 *
485486 * @return the environment and value for `this` owned by the given method.
486487 */
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)
488490 env match
489491 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)
492494 case NoEnv =>
493495 thisV match
494496 case ref : OfClass =>
495497 ref.outer match
496498 case outer : ThisValue =>
497- resolveEnvByOwner(meth , outer, ref.env)
499+ resolveEnvByOwner(enclosing , outer, ref.env)
498500 case _ =>
499501 // TODO: properly handle the case where ref.outer is ValueSet
500502 None
0 commit comments