@@ -336,9 +336,13 @@ object Objects:
336
336
def emptyEnv (meth : Symbol )(using Context ): Data =
337
337
new LocalEnv (Map .empty, meth, NoEnv )(valsMap = mutable.Map .empty, varsMap = mutable.Map .empty)
338
338
339
- def valValue (x : Symbol )(using data : Data , ctx : Context ): Value = data.getVal(x).get
340
-
341
- def varAddr (x : Symbol )(using data : Data , ctx : Context ): Heap .Addr = data.getVar(x).get
339
+ def valValue (x : Symbol )(using data : Data , ctx : Context , trace : Trace ): Value =
340
+ data.getVal(x) match
341
+ case Some (theValue) =>
342
+ theValue
343
+ case _ =>
344
+ report.warning(" [Internal error] Value not found " + x.show + " \n env = " + data.show + " . Calling trace:\n " + Trace .show, Trace .position)
345
+ Bottom
342
346
343
347
def getVal (x : Symbol )(using data : Data , ctx : Context ): Option [Value ] = data.getVal(x)
344
348
@@ -855,38 +859,37 @@ object Objects:
855
859
if sym.is(Flags .Mutable ) then
856
860
// Assume forward reference check is doing a good job
857
861
given Env .Data = env
858
- val addr = Env .varAddr(sym)
859
- if addr.owner == State .currentObject then
860
- Heap .read(addr)
861
- else
862
- errorReadOtherStaticObject(State .currentObject, addr.owner)
862
+ Env .getVar(sym) match
863
+ case Some (addr) =>
864
+ if addr.owner == State .currentObject then
865
+ Heap .read(addr)
866
+ else
867
+ errorReadOtherStaticObject(State .currentObject, addr.owner)
868
+ Bottom
869
+ end if
870
+ case _ =>
871
+ report.warning(" [Internal error] Variable not found " + sym.show + " \n env = " + env.show + " . Calling trace:\n " + Trace .show, Trace .position)
863
872
Bottom
864
- end if
865
873
else if sym.isPatternBound then
866
874
// TODO: handle patterns
867
875
Cold
868
876
else
869
877
given Env .Data = env
870
- try
871
- // Assume forward reference check is doing a good job
872
- val value = Env .valValue(sym)
873
- if isByNameParam(sym) then
874
- value match
875
- case fun : Fun =>
876
- given Env .Data = fun.env
877
- eval(fun.code, fun.thisV, fun.klass)
878
- case Cold =>
879
- report.warning(" Calling cold by-name alias. Call trace: \n " + Trace .show, Trace .position)
880
- Bottom
881
- case _ : RefSet | _ : Ref =>
882
- report.warning(" [Internal error] Unexpected by-name value " + value.show + " . Calling trace:\n " + Trace .show, Trace .position)
883
- Bottom
884
- else
885
- value
886
-
887
- catch ex =>
888
- report.warning(" [Internal error] Not found " + sym.show + " \n env = " + env.show + " . Calling trace:\n " + Trace .show, Trace .position)
889
- Bottom
878
+ // Assume forward reference check is doing a good job
879
+ val value = Env .valValue(sym)
880
+ if isByNameParam(sym) then
881
+ value match
882
+ case fun : Fun =>
883
+ given Env .Data = fun.env
884
+ eval(fun.code, fun.thisV, fun.klass)
885
+ case Cold =>
886
+ report.warning(" Calling cold by-name alias. Call trace: \n " + Trace .show, Trace .position)
887
+ Bottom
888
+ case _ : RefSet | _ : Ref =>
889
+ report.warning(" [Internal error] Unexpected by-name value " + value.show + " . Calling trace:\n " + Trace .show, Trace .position)
890
+ Bottom
891
+ else
892
+ value
890
893
891
894
case _ =>
892
895
if isByNameParam(sym) then
@@ -908,11 +911,14 @@ object Objects:
908
911
Env .resolveEnv(sym.enclosingMethod, thisV, summon[Env .Data ]) match
909
912
case Some (thisV -> env) =>
910
913
given Env .Data = env
911
- val addr = Env .varAddr(sym)
912
- if addr.owner != State .currentObject then
913
- errorMutateOtherStaticObject(State .currentObject, addr.owner)
914
- else
915
- Heap .write(addr, value)
914
+ Env .getVar(sym) match
915
+ case Some (addr) =>
916
+ if addr.owner != State .currentObject then
917
+ errorMutateOtherStaticObject(State .currentObject, addr.owner)
918
+ else
919
+ Heap .write(addr, value)
920
+ case _ =>
921
+ report.warning(" [Internal error] Variable not found " + sym.show + " \n env = " + env.show + " . Calling trace:\n " + Trace .show, Trace .position)
916
922
917
923
case _ =>
918
924
report.warning(" Assigning to variables in outer scope. Calling trace:\n " + Trace .show, Trace .position)
0 commit comments