@@ -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
@@ -703,7 +704,7 @@ class Objects(using Context @constructorOnly):
703704 a match
704705 case UnknownValue => UnknownValue
705706 case Package (_) => a
706- case BaseValue => BaseValue
707+ case SafeValue => SafeValue
707708 case ref : Ref => if ref.klass.isSubClass(klass) then ref else Bottom
708709 case ValueSet (values) => values.map(v => v.filterClass(klass)).join
709710 case arr : OfArray => if defn.ArrayClass .isSubClass(klass) then arr else Bottom
@@ -745,8 +746,8 @@ class Objects(using Context @constructorOnly):
745746 report.warning(" [Internal error] Unexpected call on package = " + value.show + " , meth = " + meth.show + Trace .show, Trace .position)
746747 Bottom
747748
748- case BaseValue =>
749- if reportUnknown then UnknownValue else BaseValue
749+ case SafeValue =>
750+ SafeValue // Check return type, if not safe, try to analyze body, 1.until(2).map(i => UninitializedObject)
750751
751752 case Bottom =>
752753 Bottom
@@ -773,7 +774,7 @@ class Objects(using Context @constructorOnly):
773774 Bottom
774775 else
775776 // Array.length is OK
776- BaseValue
777+ SafeValue
777778
778779 case ref : Ref =>
779780 val isLocal = ! meth.owner.isClass
@@ -794,10 +795,10 @@ class Objects(using Context @constructorOnly):
794795 arr
795796 else if target.equals(defn.Predef_classOf ) then
796797 // Predef.classOf is a stub method in tasty and is replaced in backend
797- BaseValue
798+ SafeValue
798799 else if target.equals(defn.ClassTagModule_apply ) then
799800 // ClassTag and other reflection related values are considered safe
800- BaseValue
801+ SafeValue
801802 else if target.hasSource then
802803 val cls = target.owner.enclosingClass.asClass
803804 val ddef = target.defTree.asInstanceOf [DefDef ]
@@ -911,8 +912,8 @@ class Objects(using Context @constructorOnly):
911912 else
912913 UnknownValue
913914
914- case BaseValue =>
915- if reportUnknown then UnknownValue else BaseValue
915+ case SafeValue =>
916+ SafeValue
916917
917918 case Package (packageSym) =>
918919 if field.isStaticObject then
@@ -996,7 +997,7 @@ class Objects(using Context @constructorOnly):
996997 case arr : OfArray =>
997998 report.warning(" [Internal error] unexpected tree in assignment, array = " + arr.show + " field = " + field + Trace .show, Trace .position)
998999
999- case BaseValue | UnknownValue =>
1000+ case SafeValue | UnknownValue =>
10001001 report.warning(" Assigning to base or unknown value is forbidden. " + Trace .show, Trace .position)
10011002
10021003 case ValueSet (values) =>
@@ -1028,7 +1029,7 @@ class Objects(using Context @constructorOnly):
10281029 */
10291030 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) {
10301031 outer.filterClass(klass.owner) match
1031- case _ : Fun | _ : OfArray | BaseValue =>
1032+ case _ : Fun | _ : OfArray | SafeValue =>
10321033 report.warning(" [Internal error] unexpected outer in instantiating a class, outer = " + outer.show + " , class = " + klass.show + " , " + Trace .show, Trace .position)
10331034 Bottom
10341035
@@ -1125,7 +1126,7 @@ class Objects(using Context @constructorOnly):
11251126 case UnknownValue =>
11261127 report.warning(" Calling on unknown value. " + Trace .show, Trace .position)
11271128 Bottom
1128- case _ : ValueSet | _ : Ref | _ : OfArray | _ : Package | BaseValue =>
1129+ case _ : ValueSet | _ : Ref | _ : OfArray | _ : Package | SafeValue =>
11291130 report.warning(" [Internal error] Unexpected by-name value " + value.show + " . " + Trace .show, Trace .position)
11301131 Bottom
11311132 else
@@ -1314,7 +1315,7 @@ class Objects(using Context @constructorOnly):
13141315 evalType(expr.tpe, thisV, klass)
13151316
13161317 case Literal (_) =>
1317- BaseValue
1318+ SafeValue
13181319
13191320 case Typed (expr, tpt) =>
13201321 if tpt.tpe.hasAnnotation(defn.UncheckedAnnot ) then
@@ -1600,7 +1601,7 @@ class Objects(using Context @constructorOnly):
16001601
16011602 // call .apply
16021603 val applyDenot = getMemberMethod(scrutineeType, nme.apply, applyType(elemType))
1603- val applyRes = call(scrutinee, applyDenot.symbol, ArgInfo (BaseValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
1604+ val applyRes = call(scrutinee, applyDenot.symbol, ArgInfo (SafeValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
16041605
16051606 if isWildcardStarArgList(pats) then
16061607 if pats.size == 1 then
@@ -1611,7 +1612,7 @@ class Objects(using Context @constructorOnly):
16111612 else
16121613 // call .drop
16131614 val dropDenot = getMemberMethod(scrutineeType, nme.drop, dropType(elemType))
1614- val dropRes = call(scrutinee, dropDenot.symbol, ArgInfo (BaseValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
1615+ val dropRes = call(scrutinee, dropDenot.symbol, ArgInfo (SafeValue , summon[Trace ], EmptyTree ) :: Nil , scrutineeType, superType = NoType , needResolve = true )
16151616 for pat <- pats.init do evalPattern(applyRes, pat)
16161617 evalPattern(dropRes, pats.last)
16171618 end if
@@ -1653,7 +1654,7 @@ class Objects(using Context @constructorOnly):
16531654 def evalType (tp : Type , thisV : ThisValue , klass : ClassSymbol , elideObjectAccess : Boolean = false ): Contextual [Value ] = log(" evaluating " + tp.show, printer, (_ : Value ).show) {
16541655 tp match
16551656 case _ : ConstantType =>
1656- BaseValue
1657+ SafeValue
16571658
16581659 case tmref : TermRef if tmref.prefix == NoPrefix =>
16591660 val sym = tmref.symbol
@@ -1903,7 +1904,7 @@ class Objects(using Context @constructorOnly):
19031904 resolveThis(target, ref.outerValue(klass), outerCls)
19041905 case ValueSet (values) =>
19051906 values.map(ref => resolveThis(target, ref, klass)).join
1906- case _ : Fun | _ : OfArray | _ : Package | BaseValue =>
1907+ case _ : Fun | _ : OfArray | _ : Package | SafeValue =>
19071908 report.warning(" [Internal error] unexpected thisV = " + thisV + " , target = " + target.show + " , klass = " + klass.show + Trace .show, Trace .position)
19081909 Bottom
19091910 }
0 commit comments