@@ -198,6 +198,12 @@ object Objects:
198
198
199
199
def widen (height : Int )(using Context ): Data =
200
200
new LocalEnv (params.map(_ -> _.widen(height)), owner, outer.widen(height))
201
+
202
+ override def toString () =
203
+ " params: " + params + " \n " +
204
+ " locals: " + locals + " \n " +
205
+ " outer {\n " + outer + " \n }"
206
+
201
207
end LocalEnv
202
208
203
209
object NoEnv extends Data :
@@ -249,19 +255,19 @@ object Objects:
249
255
* @param thisV The value for `this` of the enclosing class where the local variable is referenced.
250
256
* @param env The local environment where the local variable is referenced.
251
257
*/
252
- def resolveDefinitionEnv (sym : Symbol , thisV : Value , env : Data ): Option [(Value , Data )] =
253
- if env.contains(sym) then Some (thisV -> env)
254
- else
255
- env match
256
- case localEnv : LocalEnv =>
257
- resolveDefinitionEnv(sym, thisV, localEnv.outer)
258
- case NoEnv =>
259
- // TODO: handle RefSet
260
- thisV match
261
- case ref : OfClass =>
262
- resolveDefinitionEnv(sym, ref.outer, ref.env)
263
- case _ =>
264
- None
258
+ def resolveDefinitionEnv (sym : Symbol , thisV : Value , env : Data )( using Context ) : Option [(Value , Data )] =
259
+ env match
260
+ case localEnv : LocalEnv =>
261
+ if localEnv.owner == sym.owner then Some (thisV -> env)
262
+ else resolveDefinitionEnv(sym, thisV, localEnv.outer)
263
+ case NoEnv =>
264
+ // TODO: handle RefSet
265
+ thisV match
266
+ case ref : OfClass =>
267
+ resolveDefinitionEnv(sym, ref.outer, ref.env)
268
+ case _ =>
269
+ None
270
+ end resolveDefinitionEnv
265
271
end Env
266
272
267
273
/** Abstract heap for mutable fields
@@ -791,7 +797,7 @@ object Objects:
791
797
val value = eval(rhs, thisV, klass)
792
798
793
799
if isLocal then
794
- writeLocal(receiver. asInstanceOf [ Ref ] , lhs.symbol, value)
800
+ writeLocal(thisV , lhs.symbol, value)
795
801
else
796
802
withTrace(trace2) { assign(receiver, lhs.symbol, value, rhs.tpe) }
797
803
@@ -847,7 +853,7 @@ object Objects:
847
853
// local val definition
848
854
val rhs = eval(vdef.rhs, thisV, klass)
849
855
val sym = vdef.symbol
850
- initLocal(ref .asInstanceOf [Ref ], vdef.symbol, rhs)
856
+ initLocal(thisV .asInstanceOf [Ref ], vdef.symbol, rhs)
851
857
Bottom
852
858
853
859
case ddef : DefDef =>
0 commit comments