@@ -82,6 +82,8 @@ object Objects:
82
82
protected val vars : mutable.Map [Symbol , Heap .Addr ] = varsMap
83
83
protected val outers : mutable.Map [ClassSymbol , Value ] = outersMap
84
84
85
+ def isObjectRef : Boolean = this .isInstanceOf [ObjectRef ]
86
+
85
87
def klass : ClassSymbol
86
88
87
89
def valValue (sym : Symbol ): Value = vals(sym)
@@ -479,6 +481,7 @@ object Objects:
479
481
val empty : Data = Nil
480
482
def extend (pos : SourcePosition )(using data : Data ): Data = pos :: data
481
483
def exists (pos : SourcePosition )(using data : Data ): Boolean = data.indexOf(pos) >= 0
484
+ def show (using data : Data , ctx : Context ): String = data.map(_.show).mkString(" [" , " , " , " ]" )
482
485
483
486
inline def cache (using c : Cache .Data ): Cache .Data = c
484
487
@@ -663,11 +666,17 @@ object Objects:
663
666
else
664
667
errorReadOtherStaticObject(State .currentObject, addr.owner)
665
668
Bottom
669
+ else if ref.isObjectRef then
670
+ report.warning(" Access uninitialized field " + field.show + " . Call trace: " + Trace .show, Trace .position)
671
+ Bottom
666
672
else
667
673
// initialization error, reported by the initialization checker
668
674
Bottom
669
675
else if ref.hasVal(target) then
670
676
ref.valValue(target)
677
+ else if ref.isObjectRef then
678
+ report.warning(" Access uninitialized field " + field.show + " . Call trace: " + Trace .show, Trace .position)
679
+ Bottom
671
680
else
672
681
// initialization error, reported by the initialization checker
673
682
Bottom
@@ -865,7 +874,7 @@ object Objects:
865
874
* @param klass The enclosing class where the expression is located.
866
875
* @param cacheResult It is used to reduce the size of the cache.
867
876
*/
868
- def eval (expr : Tree , thisV : Value , klass : ClassSymbol , cacheResult : Boolean = false ): Contextual [Value ] = log(" evaluating " + expr.show + " , this = " + thisV.show + " in " + klass.show, printer, (_ : Value ).show) {
877
+ def eval (expr : Tree , thisV : Value , klass : ClassSymbol , cacheResult : Boolean = false ): Contextual [Value ] = log(" evaluating " + expr.show + " , this = " + thisV.show + " , regions = " + Regions .show + " in " + klass.show, printer, (_ : Value ).show) {
869
878
cache.cachedEval(thisV, expr, cacheResult) { expr => cases(expr, thisV, klass) }
870
879
}
871
880
@@ -956,6 +965,14 @@ object Objects:
956
965
case Typed (expr, tpt) =>
957
966
if tpt.tpe.hasAnnotation(defn.UncheckedAnnot ) then
958
967
Bottom
968
+ else if tpt.tpe.hasAnnotation(defn.InitRegionAnnot ) then
969
+ val regions2 = Regions .extend(tpt.sourcePos)
970
+ if Regions .exists(tpt.sourcePos) then
971
+ report.warning(" Cyclic region detected. Trace: " + Trace .show, tpt.sourcePos)
972
+ Bottom
973
+ else
974
+ given Regions .Data = regions2
975
+ eval(expr, thisV, klass)
959
976
else
960
977
eval(expr, thisV, klass)
961
978
@@ -997,8 +1014,10 @@ object Objects:
997
1014
evalExprs(cond :: thenp :: elsep :: Nil , thisV, klass).join
998
1015
999
1016
case Annotated (arg, annot) =>
1000
- if (expr.tpe.hasAnnotation(defn.UncheckedAnnot )) Bottom
1001
- else eval(arg, thisV, klass)
1017
+ if expr.tpe.hasAnnotation(defn.UncheckedAnnot ) then
1018
+ Bottom
1019
+ else
1020
+ eval(arg, thisV, klass)
1002
1021
1003
1022
case Match (selector, cases) =>
1004
1023
eval(selector, thisV, klass)
0 commit comments