@@ -93,7 +93,7 @@ class Objects(using Context @constructorOnly):
9393 * | OfClass(class, vs[outer], ctor, args, env) // instance of a class
9494 * | OfArray(object[owner], regions)
9595 * | Fun(..., env) // value elements that can be contained in ValueSet
96- * | BaseValue // Int, String, etc.
96+ * | SafeValue // values on which method calls and fields won't cause warnings. Int, String, etc.
9797 * vs ::= ValueSet(ve) // set of abstract values
9898 * Bottom ::= ValueSet(Empty)
9999 * val ::= ve | UnknownValue | vs | Package // all possible abstract values in domain
@@ -229,8 +229,9 @@ class Objects(using Context @constructorOnly):
229229
230230 /** Represents common base values like Int, String, etc.
231231 */
232- case object BaseValue extends ValueElement :
233- def show (using Context ): String = " BaseValue"
232+ case object SafeValue extends ValueElement :
233+ val safeTypes = defn.ScalaNumericValueTypeList ++ List (defn.UnitType , defn.BooleanType , defn.StringType )
234+ def show (using Context ): String = " SafeValue"
234235
235236 /**
236237 * Represents a set of values
@@ -668,7 +669,7 @@ class Objects(using Context @constructorOnly):
668669 a match
669670 case UnknownValue => UnknownValue
670671 case Package (_) => a
671- case BaseValue => BaseValue
672+ case SafeValue => SafeValue
672673 case ref : Ref => if ref.klass.isSubClass(klass) then ref else Bottom
673674 case ValueSet (values) => values.map(v => v.filterClass(klass)).join
674675 case arr : OfArray => if defn.ArrayClass .isSubClass(klass) then arr else Bottom
@@ -710,8 +711,8 @@ class Objects(using Context @constructorOnly):
710711 report.warning(" [Internal error] Unexpected call on package = " + value.show + " , meth = " + meth.show + Trace .show, Trace .position)
711712 Bottom
712713
713- case BaseValue =>
714- if reportUnknown then UnknownValue else BaseValue
714+ case SafeValue =>
715+ SafeValue // Check return type, if not safe, try to analyze body, 1.until(2).map(i => UninitializedObject)
715716
716717 case Bottom =>
717718 Bottom
@@ -738,7 +739,7 @@ class Objects(using Context @constructorOnly):
738739 Bottom
739740 else
740741 // Array.length is OK
741- BaseValue
742+ SafeValue
742743
743744 case ref : Ref =>
744745 val isLocal = ! meth.owner.isClass
@@ -759,10 +760,10 @@ class Objects(using Context @constructorOnly):
759760 arr
760761 else if target.equals(defn.Predef_classOf ) then
761762 // Predef.classOf is a stub method in tasty and is replaced in backend
762- BaseValue
763+ SafeValue
763764 else if target.equals(defn.ClassTagModule_apply ) then
764765 // ClassTag and other reflection related values are considered safe
765- BaseValue
766+ SafeValue
766767 else if target.hasSource then
767768 val cls = target.owner.enclosingClass.asClass
768769 val ddef = target.defTree.asInstanceOf [DefDef ]
@@ -876,8 +877,8 @@ class Objects(using Context @constructorOnly):
876877 else
877878 UnknownValue
878879
879- case BaseValue =>
880- if reportUnknown then UnknownValue else BaseValue
880+ case SafeValue =>
881+ SafeValue
881882
882883 case Package (packageSym) =>
883884 if field.isStaticObject then
@@ -961,7 +962,7 @@ class Objects(using Context @constructorOnly):
961962 case arr : OfArray =>
962963 report.warning(" [Internal error] unexpected tree in assignment, array = " + arr.show + " field = " + field + Trace .show, Trace .position)
963964
964- case BaseValue | UnknownValue =>
965+ case SafeValue | UnknownValue =>
965966 report.warning(" Assigning to base or unknown value is forbidden. " + Trace .show, Trace .position)
966967
967968 case ValueSet (values) =>
@@ -993,7 +994,7 @@ class Objects(using Context @constructorOnly):
993994 */
994995 def instantiate (outer : Value , klass : ClassSymbol , ctor : Symbol , args : List [ArgInfo ]): Contextual [Value ] = log(" instantiating " + klass.show + " , outer = " + outer + " , args = " + args.map(_.value.show), printer, (_ : Value ).show) {
995996 outer.filterClass(klass.owner) match
996- case _ : Fun | _ : OfArray | BaseValue =>
997+ case _ : Fun | _ : OfArray | SafeValue =>
997998 report.warning(" [Internal error] unexpected outer in instantiating a class, outer = " + outer.show + " , class = " + klass.show + " , " + Trace .show, Trace .position)
998999 Bottom
9991000
@@ -1088,7 +1089,7 @@ class Objects(using Context @constructorOnly):
10881089 case UnknownValue =>
10891090 report.warning(" Calling on unknown value. " + Trace .show, Trace .position)
10901091 Bottom
1091- case _ : ValueSet | _ : Ref | _ : OfArray | _ : Package | BaseValue =>
1092+ case _ : ValueSet | _ : Ref | _ : OfArray | _ : Package | SafeValue =>
10921093 report.warning(" [Internal error] Unexpected by-name value " + value.show + " . " + Trace .show, Trace .position)
10931094 Bottom
10941095 else
@@ -1276,7 +1277,7 @@ class Objects(using Context @constructorOnly):
12761277 evalType(expr.tpe, thisV, klass)
12771278
12781279 case Literal (_) =>
1279- BaseValue
1280+ SafeValue
12801281
12811282 case Typed (expr, tpt) =>
12821283 if tpt.tpe.hasAnnotation(defn.UncheckedAnnot ) then
@@ -1562,7 +1563,7 @@ class Objects(using Context @constructorOnly):
15621563
15631564 // call .apply
15641565 val applyDenot = getMemberMethod(scrutineeType, nme.apply, applyType(elemType))
1565- val applyRes = call(scrutinee, applyDenot.symbol, ArgInfo (BaseValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
1566+ val applyRes = call(scrutinee, applyDenot.symbol, ArgInfo (SafeValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
15661567
15671568 if isWildcardStarArgList(pats) then
15681569 if pats.size == 1 then
@@ -1573,7 +1574,7 @@ class Objects(using Context @constructorOnly):
15731574 else
15741575 // call .drop
15751576 val dropDenot = getMemberMethod(scrutineeType, nme.drop, dropType(elemType))
1576- val dropRes = call(scrutinee, dropDenot.symbol, ArgInfo (BaseValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
1577+ val dropRes = call(scrutinee, dropDenot.symbol, ArgInfo (SafeValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
15771578 for pat <- pats.init do evalPattern(applyRes, pat)
15781579 evalPattern(dropRes, pats.last)
15791580 end if
@@ -1615,7 +1616,7 @@ class Objects(using Context @constructorOnly):
16151616 def evalType (tp : Type , thisV : ThisValue , klass : ClassSymbol , elideObjectAccess : Boolean = false ): Contextual [Value ] = log(" evaluating " + tp.show, printer, (_ : Value ).show) {
16161617 tp match
16171618 case _ : ConstantType =>
1618- BaseValue
1619+ SafeValue
16191620
16201621 case tmref : TermRef if tmref.prefix == NoPrefix =>
16211622 val sym = tmref.symbol
@@ -1865,7 +1866,7 @@ class Objects(using Context @constructorOnly):
18651866 resolveThis(target, ref.outerValue(klass), outerCls)
18661867 case ValueSet (values) =>
18671868 values.map(ref => resolveThis(target, ref, klass)).join
1868- case _ : Fun | _ : OfArray | _ : Package | BaseValue =>
1869+ case _ : Fun | _ : OfArray | _ : Package | SafeValue =>
18691870 report.warning(" [Internal error] unexpected thisV = " + thisV + " , target = " + target.show + " , klass = " + klass.show + Trace .show, Trace .position)
18701871 Bottom
18711872 }
0 commit comments