@@ -60,13 +60,43 @@ private predicate candidateMethod(RefType t, Method m, string name, int numParam
60
60
not whitelist ( name )
61
61
}
62
62
63
- pragma [ inline]
64
- private predicate potentiallyConfusingTypes ( Type a , Type b ) {
65
- exists ( RefType commonSubtype | hasSubtypeOrInstantiation * ( a , commonSubtype ) |
66
- hasSubtypeOrInstantiation * ( b , commonSubtype )
63
+ predicate paramTypePair ( Type t1 , Type t2 ) {
64
+ exists ( Method n , Method m , int i |
65
+ overloadedMethodsMostSpecific ( n , m ) and
66
+ t1 = n .getParameterType ( i ) and
67
+ t2 = m .getParameterType ( i )
67
68
)
69
+ }
70
+
71
+ // handle simple cases separately
72
+ predicate potentiallyConfusingTypesSimple ( Type t1 , Type t2 ) {
73
+ paramTypePair ( t1 , t2 ) and
74
+ (
75
+ t1 = t2
76
+ or
77
+ t1 instanceof TypeObject and t2 instanceof RefType
78
+ or
79
+ t2 instanceof TypeObject and t1 instanceof RefType
80
+ or
81
+ confusingPrimitiveBoxedTypes ( t1 , t2 )
82
+ )
83
+ }
84
+
85
+ // check erased types first
86
+ predicate potentiallyConfusingTypesRefTypes ( RefType t1 , RefType t2 ) {
87
+ paramTypePair ( t1 , t2 ) and
88
+ not potentiallyConfusingTypesSimple ( t1 , t2 ) and
89
+ haveIntersection ( t1 , t2 )
90
+ }
91
+
92
+ // then check hasSubtypeOrInstantiation
93
+ predicate potentiallyConfusingTypes ( Type t1 , Type t2 ) {
94
+ potentiallyConfusingTypesSimple ( t1 , t2 )
68
95
or
69
- confusingPrimitiveBoxedTypes ( a , b )
96
+ potentiallyConfusingTypesRefTypes ( t1 , t2 ) and
97
+ exists ( RefType commonSubtype | hasSubtypeOrInstantiation * ( t1 , commonSubtype ) |
98
+ hasSubtypeOrInstantiation * ( t2 , commonSubtype )
99
+ )
70
100
}
71
101
72
102
private predicate hasSubtypeOrInstantiation ( RefType t , RefType sub ) {
0 commit comments