@@ -44,43 +44,39 @@ string getKind(MemberDeclaration m) {
4444 * A call-signature that originates from a MethodSignature in the AST.
4545 */
4646private class MethodCallSig extends CallSignatureType {
47- string name ;
48-
49- MethodCallSig ( ) {
50- exists ( MethodSignature sig |
51- this = sig .getBody ( ) .getCallSignature ( ) and
52- name = sig .getName ( )
53- )
54- }
55-
56- /**
57- * Gets the name of any member that has this signature.
58- */
59- string getName ( ) {
60- result = name
61- }
47+ string name ;
48+
49+ MethodCallSig ( ) {
50+ exists ( MethodSignature sig |
51+ this = sig .getBody ( ) .getCallSignature ( ) and
52+ name = sig .getName ( )
53+ )
54+ }
55+
56+ /**
57+ * Gets the name of any member that has this signature.
58+ */
59+ string getName ( ) { result = name }
6260}
6361
6462/**
6563 * Holds if the two call signatures could be overloads of each other and have the same parameter types.
6664 */
6765predicate matchingCallSignature ( MethodCallSig method , MethodCallSig other ) {
68- method .getName ( ) = other .getName ( ) and
69-
66+ method .getName ( ) = other .getName ( ) and
7067 method .getNumOptionalParameter ( ) = other .getNumOptionalParameter ( ) and
7168 method .getNumParameter ( ) = other .getNumParameter ( ) and
7269 method .getNumRequiredParameter ( ) = other .getNumRequiredParameter ( ) and
73- // purposely not looking at number of type arguments.
74-
75- method .getKind ( ) = other .getKind ( ) and
76-
77-
78- forall ( int i | i in [ 0 .. - 1 + method .getNumParameter ( ) ] |
70+ // purposely not looking at number of type arguments.
71+ method .getKind ( ) = other .getKind ( ) and
72+ forall ( int i | i in [ 0 .. - 1 + method .getNumParameter ( ) ] |
7973 method .getParameter ( i ) = other .getParameter ( i ) // This is sometimes imprecise, so it is still a good idea to compare type annotations.
80- ) and
81-
82- // shared type parameters are equal.
83- forall ( int i | i in [ 0 .. - 1 + min ( int num | num = method .getNumTypeParameter ( ) or num = other .getNumTypeParameter ( ) ) ] |
74+ ) and
75+ // shared type parameters are equal.
76+ forall ( int i |
77+ i in [ 0 .. - 1 +
78+ min ( int num | num = method .getNumTypeParameter ( ) or num = other .getNumTypeParameter ( ) ) ]
79+ |
8480 method .getTypeParameterBound ( i ) = other .getTypeParameterBound ( i )
8581 )
8682}
@@ -89,7 +85,7 @@ predicate matchingCallSignature(MethodCallSig method, MethodCallSig other) {
8985 * Gets which overload index the MethodSignature has among the overloads of the same name.
9086 */
9187int getOverloadIndex ( MethodSignature sig ) {
92- sig .getDeclaringType ( ) .getMethodOverload ( sig .getName ( ) , result ) = sig
88+ sig .getDeclaringType ( ) .getMethodOverload ( sig .getName ( ) , result ) = sig
9389}
9490
9591/**
@@ -100,41 +96,34 @@ predicate signaturesMatch(MethodSignature method, MethodSignature other) {
10096 method .getDeclaringType ( ) = other .getDeclaringType ( ) and
10197 // same static modifier.
10298 getKind ( method ) = getKind ( other ) and
103-
10499 // same name.
105100 method .getName ( ) = other .getName ( ) and
106-
107101 // same number of parameters.
108102 method .getBody ( ) .getNumParameter ( ) = other .getBody ( ) .getNumParameter ( ) and
109-
110103 // The types are compared in matchingCallSignature. This is sanity-check that the textual representation of the type-annotations are somewhat similar.
111104 forall ( int i | i in [ 0 .. - 1 + method .getBody ( ) .getNumParameter ( ) ] |
112- getParameterTypeAnnotation ( method , i ) = getParameterTypeAnnotation ( other , i )
105+ getParameterTypeAnnotation ( method , i ) = getParameterTypeAnnotation ( other , i )
113106 ) and
114-
115107 matchingCallSignature ( method .getBody ( ) .getCallSignature ( ) , other .getBody ( ) .getCallSignature ( ) )
116108}
117109
118110from ClassOrInterface decl , string name , MethodSignature previous , MethodSignature unreachable
119111where
120112 previous = decl .getMethod ( name ) and
121113 unreachable = getOtherMatchingSignatures ( previous ) and
122-
123114 // If the method is part of inheritance between classes/interfaces, then there can sometimes be reasons for having this pattern.
124- not exists ( decl .getASuperTypeDeclaration ( ) .getMethod ( name ) ) and
125- not exists ( ClassOrInterface sub |
115+ not exists ( decl .getASuperTypeDeclaration ( ) .getMethod ( name ) ) and
116+ not exists ( ClassOrInterface sub |
126117 decl = sub .getASuperTypeDeclaration ( ) and
127118 exists ( sub .getMethod ( name ) )
128119 ) and
129-
130-
131120 // If a later method overload has more type parameters, then that overload can be selected by explicitly declaring the type arguments at the callsite.
132121 // This comparison removes those cases.
133122 unreachable .getBody ( ) .getNumTypeParameter ( ) <= previous .getBody ( ) .getNumTypeParameter ( ) and
134-
135123 // We always select the first of the overloaded methods.
136124 not exists ( MethodSignature later | later = getOtherMatchingSignatures ( previous ) |
137125 getOverloadIndex ( later ) < getOverloadIndex ( previous )
138126 )
139127select unreachable ,
140- "This overload of " + name + "() is unreachable, the $@ overload will always be selected." , previous , "previous"
128+ "This overload of " + name + "() is unreachable, the $@ overload will always be selected." ,
129+ previous , "previous"
0 commit comments