@@ -206,49 +206,41 @@ public boolean hasCompatibleTypesForCall(AccessPath apBase, SootClass dest) {
206206 * @return The more precise one of the two given types
207207 */
208208 public Type getMorePreciseType (Type possibleRefinement , Type declType ) {
209- final FastHierarchy fastHierarchy = scene .getOrMakeFastHierarchy ();
210-
211- if (declType == null )
212- return possibleRefinement ;
213- else if (possibleRefinement == null )
214- return declType ;
215- else if (declType == possibleRefinement )
216- return declType ;
217- else if (TypeUtils .isObjectLikeType (declType ))
218- return possibleRefinement ;
219- else if (TypeUtils .isObjectLikeType (possibleRefinement ))
220- return declType ;
221- else if (declType instanceof PrimType && possibleRefinement instanceof PrimType )
222- return null ;
223- else if (fastHierarchy .canStoreType (possibleRefinement , declType ))
224- return possibleRefinement ;
225- else if (fastHierarchy .canStoreType (declType , possibleRefinement ))
226- return declType ;
227- else {
228- // If one type is an array type and the other one is the base type,
229- // we still accept the cast
230- if (declType instanceof ArrayType && possibleRefinement instanceof ArrayType ) {
231- ArrayType at1 = (ArrayType ) possibleRefinement ;
232- ArrayType at2 = (ArrayType ) declType ;
233- if (at1 .numDimensions != at2 .numDimensions )
234- return null ;
235- Type preciseType = getMorePreciseType (at1 .getElementType (), at2 .getElementType ());
236- if (preciseType == null )
237- return null ;
238-
239- return ArrayType .v (preciseType , at2 .numDimensions );
240- } else if (declType instanceof ArrayType ) {
241- ArrayType at = (ArrayType ) declType ;
242- Type preciseType = getMorePreciseType (possibleRefinement , at .getElementType ());
243- if (preciseType == null )
244- return null ;
245-
246- return ArrayType .v (preciseType , at .numDimensions );
247- } else if (possibleRefinement instanceof ArrayType ) {
248- ArrayType at = (ArrayType ) possibleRefinement ;
249- return getMorePreciseType (at .getElementType (), declType );
250- }
209+ if (declType instanceof ArrayType && possibleRefinement instanceof ArrayType ) {
210+ ArrayType at = (ArrayType ) declType ;
211+ Type morePreciseType = getMorePreciseType (((ArrayType ) possibleRefinement ).baseType , at .baseType );
212+ if (morePreciseType != null )
213+ return ArrayType .v (morePreciseType , at .numDimensions );
214+ } else if (declType instanceof ArrayType ) {
215+ ArrayType at = (ArrayType ) declType ;
216+ Type morePreciseType = getMorePreciseType (possibleRefinement , at .baseType );
217+ if (morePreciseType != null )
218+ return ArrayType .v (morePreciseType , at .numDimensions );
219+ } else if (possibleRefinement instanceof ArrayType ) {
220+ return getMorePreciseType (((ArrayType ) possibleRefinement ).baseType , declType );
221+ } else {
222+ final FastHierarchy fastHierarchy = scene .getOrMakeFastHierarchy ();
223+
224+ if (declType == null )
225+ return possibleRefinement ;
226+ else if (possibleRefinement == null )
227+ return declType ;
228+ else if (declType == possibleRefinement )
229+ return declType ;
230+ // Prevent declType=Object and refinement=String[] from returning String[]
231+ // See testTypeNarrowing2
232+ else if (TypeUtils .isObjectLikeType (declType ))
233+ return possibleRefinement ;
234+ else if (TypeUtils .isObjectLikeType (possibleRefinement ))
235+ return declType ;
236+ else if (declType instanceof PrimType && possibleRefinement instanceof PrimType )
237+ return null ;
238+ else if (fastHierarchy .canStoreType (possibleRefinement , declType ))
239+ return possibleRefinement ;
240+ else if (fastHierarchy .canStoreType (declType , possibleRefinement ))
241+ return declType ;
251242 }
243+
252244 return null ;
253245 }
254246
0 commit comments