Skip to content

Commit b3cbf8b

Browse files
authored
Merge pull request #2960 from erik-krogh/OverloadsWithThis
Approved by asgerf
2 parents e1c5449 + 68fb8c5 commit b3cbf8b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-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().getType() = other.getBody().getThisTypeAnnotation().getType()
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
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:21:3:21:28 | bar(thi ... number; | This overload of bar() is unreachable, the $@ overload will always be selected. | tst.ts:20:3:20:28 | bar(thi ... string; | previous |
5+
| tst.ts:27:3:27:30 | method( ... number; | This overload of method() is unreachable, the $@ overload will always be selected. | tst.ts:26:3:26:30 | method( ... string; | previous |

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ 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+
20+
bar(this: number): string;
21+
bar(this: number): number; // NOT OK
22+
1723
}
1824

1925
declare class Base {

0 commit comments

Comments
 (0)