Skip to content

Commit 488ed1f

Browse files
committed
Be better at determining this usage in methods, accept baselines
1 parent 586bb7b commit 488ed1f

14 files changed

+46
-42
lines changed

src/compiler/checker.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15860,8 +15860,8 @@ namespace ts {
1586015860
outerTypeParameters = addRange(outerTypeParameters, templateTagParameters);
1586115861
}
1586215862
typeParameters = outerTypeParameters || emptyArray;
15863-
typeParameters = (target.objectFlags & ObjectFlags.Reference || target.symbol.flags & SymbolFlags.TypeLiteral) && !target.aliasTypeArguments ?
15864-
filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration)) :
15863+
typeParameters = (target.objectFlags & ObjectFlags.Reference || target.symbol.flags & SymbolFlags.Method || target.symbol.flags & SymbolFlags.TypeLiteral) && !target.aliasTypeArguments ?
15864+
filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration) || !(type.objectFlags & ObjectFlags.Reference) && some(type.symbol.declarations, d => isTypeParameterPossiblyReferenced(tp, d))) :
1586515865
typeParameters;
1586615866
links.outerTypeParameters = typeParameters;
1586715867
}
@@ -15908,7 +15908,7 @@ namespace ts {
1590815908
return true;
1590915909
}
1591015910
}
15911-
return !!forEachChild(node, containsReference);
15911+
return containsReference(node);
1591215912
}
1591315913
return true;
1591415914
function containsReference(node: Node): boolean {
@@ -15920,6 +15920,9 @@ namespace ts {
1592015920
getTypeFromTypeNodeWorker(<TypeNode>node) === tp; // use worker because we're looking for === equality
1592115921
case SyntaxKind.TypeQuery:
1592215922
return true;
15923+
case SyntaxKind.MethodDeclaration:
15924+
case SyntaxKind.MethodSignature:
15925+
return (!(node as FunctionLikeDeclaration).type && !!(node as FunctionLikeDeclaration).body) || !!forEachChild(node, containsReference);
1592315926
}
1592415927
return !!forEachChild(node, containsReference);
1592515928
}

tests/baselines/reference/bivariantInferences.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ declare const b: (string | number)[] | null[] | undefined[] | {}[];
2424

2525
let x = a.equalsShallow(b);
2626
>x : Symbol(x, Decl(bivariantInferences.ts, 9, 3))
27-
>a.equalsShallow : Symbol(Array.equalsShallow, Decl(bivariantInferences.ts, 2, 20))
27+
>a.equalsShallow : Symbol(Array.equalsShallow, Decl(bivariantInferences.ts, 2, 20), Decl(bivariantInferences.ts, 2, 20), Decl(bivariantInferences.ts, 2, 20), Decl(bivariantInferences.ts, 2, 20))
2828
>a : Symbol(a, Decl(bivariantInferences.ts, 6, 13))
29-
>equalsShallow : Symbol(Array.equalsShallow, Decl(bivariantInferences.ts, 2, 20))
29+
>equalsShallow : Symbol(Array.equalsShallow, Decl(bivariantInferences.ts, 2, 20), Decl(bivariantInferences.ts, 2, 20), Decl(bivariantInferences.ts, 2, 20), Decl(bivariantInferences.ts, 2, 20))
3030
>b : Symbol(b, Decl(bivariantInferences.ts, 7, 13))
3131

tests/baselines/reference/bivariantInferences.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ declare const b: (string | number)[] | null[] | undefined[] | {}[];
1919
let x = a.equalsShallow(b);
2020
>x : boolean
2121
>a.equalsShallow(b) : boolean
22-
>a.equalsShallow : <T>(this: readonly T[], other: readonly T[]) => boolean
22+
>a.equalsShallow : (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean)
2323
>a : (string | number)[] | null[] | undefined[] | {}[]
24-
>equalsShallow : <T>(this: readonly T[], other: readonly T[]) => boolean
24+
>equalsShallow : (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean) | (<T>(this: readonly T[], other: readonly T[]) => boolean)
2525
>b : (string | number)[] | null[] | undefined[] | {}[]
2626

tests/baselines/reference/completionEntryForUnionMethod.baseline

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
},
125125
{
126126
"text": "toString",
127-
"kind": "methodName"
127+
"kind": "propertyName"
128128
},
129129
{
130130
"text": "(",
@@ -198,7 +198,7 @@
198198
},
199199
{
200200
"text": "toLocaleString",
201-
"kind": "methodName"
201+
"kind": "propertyName"
202202
},
203203
{
204204
"text": "(",
@@ -981,7 +981,7 @@
981981
},
982982
{
983983
"text": "join",
984-
"kind": "methodName"
984+
"kind": "propertyName"
985985
},
986986
{
987987
"text": "(",

tests/baselines/reference/mixinAccessModifiers.symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,13 @@ function f9(x: ProtectedGeneric<{a: void;}> & ProtectedGeneric<{a:void;b:void;}>
387387
>b : Symbol(b, Decl(mixinAccessModifiers.ts, 127, 71))
388388

389389
x.privateMethod(); // Error, private constituent makes method inaccessible
390-
>x.privateMethod : Symbol(ProtectedGeneric.privateMethod, Decl(mixinAccessModifiers.ts, 107, 27))
390+
>x.privateMethod : Symbol(ProtectedGeneric.privateMethod, Decl(mixinAccessModifiers.ts, 107, 27), Decl(mixinAccessModifiers.ts, 107, 27))
391391
>x : Symbol(x, Decl(mixinAccessModifiers.ts, 127, 12))
392-
>privateMethod : Symbol(ProtectedGeneric.privateMethod, Decl(mixinAccessModifiers.ts, 107, 27))
392+
>privateMethod : Symbol(ProtectedGeneric.privateMethod, Decl(mixinAccessModifiers.ts, 107, 27), Decl(mixinAccessModifiers.ts, 107, 27))
393393

394394
x.protectedMethod(); // Error, protected when all constituents are protected
395-
>x.protectedMethod : Symbol(ProtectedGeneric.protectedMethod, Decl(mixinAccessModifiers.ts, 108, 27))
395+
>x.protectedMethod : Symbol(ProtectedGeneric.protectedMethod, Decl(mixinAccessModifiers.ts, 108, 27), Decl(mixinAccessModifiers.ts, 108, 27))
396396
>x : Symbol(x, Decl(mixinAccessModifiers.ts, 127, 12))
397-
>protectedMethod : Symbol(ProtectedGeneric.protectedMethod, Decl(mixinAccessModifiers.ts, 108, 27))
397+
>protectedMethod : Symbol(ProtectedGeneric.protectedMethod, Decl(mixinAccessModifiers.ts, 108, 27), Decl(mixinAccessModifiers.ts, 108, 27))
398398
}
399399

tests/baselines/reference/mixinAccessModifiers.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,14 +373,14 @@ function f9(x: ProtectedGeneric<{a: void;}> & ProtectedGeneric<{a:void;b:void;}>
373373

374374
x.privateMethod(); // Error, private constituent makes method inaccessible
375375
>x.privateMethod() : void
376-
>x.privateMethod : () => void
376+
>x.privateMethod : (() => void) & (() => void)
377377
>x : ProtectedGeneric<{ a: void; }> & ProtectedGeneric<{ a: void; b: void; }>
378-
>privateMethod : () => void
378+
>privateMethod : (() => void) & (() => void)
379379

380380
x.protectedMethod(); // Error, protected when all constituents are protected
381381
>x.protectedMethod() : void
382-
>x.protectedMethod : () => void
382+
>x.protectedMethod : (() => void) & (() => void)
383383
>x : ProtectedGeneric<{ a: void; }> & ProtectedGeneric<{ a: void; b: void; }>
384-
>protectedMethod : () => void
384+
>protectedMethod : (() => void) & (() => void)
385385
}
386386

tests/baselines/reference/sliceResultCast.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ declare var x: [number, string] | [number, string, string];
33
>x : Symbol(x, Decl(sliceResultCast.ts, 0, 11))
44

55
x.slice(1) as readonly string[];
6-
>x.slice : Symbol(Array.slice, Decl(lib.es5.d.ts, --, --))
6+
>x.slice : Symbol(Array.slice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
77
>x : Symbol(x, Decl(sliceResultCast.ts, 0, 11))
8-
>slice : Symbol(Array.slice, Decl(lib.es5.d.ts, --, --))
8+
>slice : Symbol(Array.slice, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
99

tests/baselines/reference/sliceResultCast.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ declare var x: [number, string] | [number, string, string];
55
x.slice(1) as readonly string[];
66
>x.slice(1) as readonly string[] : readonly string[]
77
>x.slice(1) : (string | number)[]
8-
>x.slice : (start?: number, end?: number) => (string | number)[]
8+
>x.slice : ((start?: number, end?: number) => (string | number)[]) | ((start?: number, end?: number) => (string | number)[])
99
>x : [number, string] | [number, string, string]
10-
>slice : (start?: number, end?: number) => (string | number)[]
10+
>slice : ((start?: number, end?: number) => (string | number)[]) | ((start?: number, end?: number) => (string | number)[])
1111
>1 : 1
1212

tests/baselines/reference/typeParameterExtendingUnion1.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function f<T extends Cat | Dog>(a: T) {
3333
>T : Symbol(T, Decl(typeParameterExtendingUnion1.ts, 8, 11))
3434

3535
a.run();
36-
>a.run : Symbol(Animal.run, Decl(typeParameterExtendingUnion1.ts, 0, 14))
36+
>a.run : Symbol(Animal.run, Decl(typeParameterExtendingUnion1.ts, 0, 14), Decl(typeParameterExtendingUnion1.ts, 0, 14))
3737
>a : Symbol(a, Decl(typeParameterExtendingUnion1.ts, 8, 32))
38-
>run : Symbol(Animal.run, Decl(typeParameterExtendingUnion1.ts, 0, 14))
38+
>run : Symbol(Animal.run, Decl(typeParameterExtendingUnion1.ts, 0, 14), Decl(typeParameterExtendingUnion1.ts, 0, 14))
3939

4040
run(a);
4141
>run : Symbol(run, Decl(typeParameterExtendingUnion1.ts, 2, 33))

tests/baselines/reference/typeParameterExtendingUnion1.types

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function f<T extends Cat | Dog>(a: T) {
3030

3131
a.run();
3232
>a.run() : void
33-
>a.run : () => void
33+
>a.run : (() => void) | (() => void)
3434
>a : Cat | Dog
35-
>run : () => void
35+
>run : (() => void) | (() => void)
3636

3737
run(a);
3838
>run(a) : void

tests/baselines/reference/typeParameterExtendingUnion2.symbols

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ function run(a: Cat | Dog) {
2020
>Dog : Symbol(Dog, Decl(typeParameterExtendingUnion2.ts, 1, 33))
2121

2222
a.run();
23-
>a.run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14))
23+
>a.run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14), Decl(typeParameterExtendingUnion2.ts, 0, 14))
2424
>a : Symbol(a, Decl(typeParameterExtendingUnion2.ts, 4, 13))
25-
>run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14))
25+
>run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14), Decl(typeParameterExtendingUnion2.ts, 0, 14))
2626
}
2727

2828
function f<T extends Cat | Dog>(a: T) {
@@ -34,9 +34,9 @@ function f<T extends Cat | Dog>(a: T) {
3434
>T : Symbol(T, Decl(typeParameterExtendingUnion2.ts, 8, 11))
3535

3636
a.run();
37-
>a.run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14))
37+
>a.run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14), Decl(typeParameterExtendingUnion2.ts, 0, 14))
3838
>a : Symbol(a, Decl(typeParameterExtendingUnion2.ts, 8, 32))
39-
>run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14))
39+
>run : Symbol(Animal.run, Decl(typeParameterExtendingUnion2.ts, 0, 14), Decl(typeParameterExtendingUnion2.ts, 0, 14))
4040

4141
run(a);
4242
>run : Symbol(run, Decl(typeParameterExtendingUnion2.ts, 2, 33))

tests/baselines/reference/typeParameterExtendingUnion2.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ function run(a: Cat | Dog) {
1919

2020
a.run();
2121
>a.run() : void
22-
>a.run : () => void
22+
>a.run : (() => void) | (() => void)
2323
>a : Cat | Dog
24-
>run : () => void
24+
>run : (() => void) | (() => void)
2525
}
2626

2727
function f<T extends Cat | Dog>(a: T) {
@@ -30,9 +30,9 @@ function f<T extends Cat | Dog>(a: T) {
3030

3131
a.run();
3232
>a.run() : void
33-
>a.run : () => void
33+
>a.run : (() => void) | (() => void)
3434
>a : Cat | Dog
35-
>run : () => void
35+
>run : (() => void) | (() => void)
3636

3737
run(a);
3838
>run(a) : void

tests/baselines/reference/types.asyncGenerators.es2018.2.errors.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
1616
Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
1717
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(19,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
1818
Call signature return types 'AsyncGenerator<string, void, undefined>' and 'AsyncIterable<number>' are incompatible.
19-
The types returned by '[Symbol.asyncIterator]().next(...)' are incompatible between these types.
20-
Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
19+
The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
20+
Type '(...args: [] | [undefined]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
2121
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(22,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
2222
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterable<number>'.
2323
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(25,7): error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterable<number>'.
2424
Call signature return types 'AsyncGenerator<string, void, unknown>' and 'AsyncIterable<number>' are incompatible.
25-
The types returned by '[Symbol.asyncIterator]().next(...)' are incompatible between these types.
26-
Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
25+
The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
26+
Type '(...args: [] | [unknown]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
2727
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(28,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
2828
Type 'AsyncGenerator<string, void, undefined>' is not assignable to type 'AsyncIterator<number, any, undefined>'.
2929
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(31,7): error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterator<number, any, undefined>'.
@@ -93,8 +93,8 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
9393
~~~~~~~~~~~~~~
9494
!!! error TS2322: Type '() => AsyncGenerator<string, void, undefined>' is not assignable to type '() => AsyncIterable<number>'.
9595
!!! error TS2322: Call signature return types 'AsyncGenerator<string, void, undefined>' and 'AsyncIterable<number>' are incompatible.
96-
!!! error TS2322: The types returned by '[Symbol.asyncIterator]().next(...)' are incompatible between these types.
97-
!!! error TS2322: Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
96+
!!! error TS2322: The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
97+
!!! error TS2322: Type '(...args: [] | [undefined]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
9898
yield "a";
9999
};
100100
const assignability5: () => AsyncIterable<number> = async function * () {
@@ -107,8 +107,8 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.es2018.2.ts(
107107
~~~~~~~~~~~~~~
108108
!!! error TS2322: Type '() => AsyncGenerator<string, void, unknown>' is not assignable to type '() => AsyncIterable<number>'.
109109
!!! error TS2322: Call signature return types 'AsyncGenerator<string, void, unknown>' and 'AsyncIterable<number>' are incompatible.
110-
!!! error TS2322: The types returned by '[Symbol.asyncIterator]().next(...)' are incompatible between these types.
111-
!!! error TS2322: Type 'Promise<IteratorResult<string, void>>' is not assignable to type 'Promise<IteratorResult<number, any>>'.
110+
!!! error TS2322: The types of '[Symbol.asyncIterator]().next' are incompatible between these types.
111+
!!! error TS2322: Type '(...args: [] | [unknown]) => Promise<IteratorResult<string, void>>' is not assignable to type '(...args: [] | [undefined]) => Promise<IteratorResult<number, any>>'.
112112
yield* (async function * () { yield "a"; })();
113113
};
114114
const assignability7: () => AsyncIterator<number> = async function * () {

tests/cases/compiler/stackDepthLimitCastingType.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// @strict: true
2+
// @skipLibCheck: true
23
// @filename: node_modules/backbone/index.d.ts
34
declare global {
45
interface JQueryXHR { }

0 commit comments

Comments
 (0)