Skip to content

Commit e0fcc4a

Browse files
committed
handle this parameters when finding unreachable overloads
1 parent 228bd73 commit e0fcc4a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

javascript/ql/src/Declarations/UnreachableMethodOverloads.ql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ predicate signaturesMatch(MethodSignature method, MethodSignature other) {
100100
method.getName() = other.getName() and
101101
// same number of parameters.
102102
method.getBody().getNumParameter() = other.getBody().getNumParameter() and
103+
// same this parameter (if exists)
104+
(
105+
not exists(method.getBody().getThisTypeAnnotation()) and
106+
not exists(other.getBody().getThisTypeAnnotation())
107+
or
108+
method.getBody().getThisTypeAnnotation() = other.getBody().getThisTypeAnnotation()
109+
) and
103110
// The types are compared in matchingCallSignature. This is sanity-check that the textual representation of the type-annotations are somewhat similar.
104111
forall(int i | i in [0 .. -1 + method.getBody().getNumParameter()] |
105112
getParameterTypeAnnotation(method, i) = getParameterTypeAnnotation(other, i)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
| tst.ts:3:3:3:30 | method( ... number; | This overload of method() is unreachable, the $@ overload will always be selected. | tst.ts:2:3:2:30 | method( ... string; | previous |
22
| tst.ts:6:3:6:17 | types1(): any[] | This overload of types1() is unreachable, the $@ overload will always be selected. | tst.ts:5:3:5:18 | types1<T>(): T[] | previous |
33
| tst.ts:15:3:15:74 | on(even ... nction; | This overload of on() is unreachable, the $@ overload will always be selected. | tst.ts:14:3:14:74 | on(even ... nction; | previous |
4-
| tst.ts:21:3:21:30 | method( ... number; | This overload of method() is unreachable, the $@ overload will always be selected. | tst.ts:20:3:20:30 | method( ... string; | previous |
4+
| tst.ts:24:3:24:30 | method( ... number; | This overload of method() is unreachable, the $@ overload will always be selected. | tst.ts:23:3:23:30 | method( ... string; | previous |

javascript/ql/test/query-tests/Declarations/UnreachableOverloads/tst.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ declare class Foobar {
1414
on(event: string, fn?: (event?: any, ...args: any[]) => void): Function;
1515
on(event: string, fn?: (event?: any, ...args: any[]) => void): Function; // NOT OK.
1616

17+
foo(this: string): string;
18+
foo(this: number): number; // OK
19+
1720
}
1821

1922
declare class Base {

0 commit comments

Comments
 (0)