Skip to content

Commit f2bd592

Browse files
authored
Always consider parameters in scope visible to node builder (#58075)
1 parent 386cc0f commit f2bd592

8 files changed

+90
-80
lines changed

src/compiler/checker.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6329,7 +6329,8 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
63296329
if (
63306330
entityName.parent.kind === SyntaxKind.TypeQuery ||
63316331
entityName.parent.kind === SyntaxKind.ExpressionWithTypeArguments && !isPartOfTypeNode(entityName.parent) ||
6332-
entityName.parent.kind === SyntaxKind.ComputedPropertyName
6332+
entityName.parent.kind === SyntaxKind.ComputedPropertyName ||
6333+
entityName.parent.kind === SyntaxKind.TypePredicate && (entityName.parent as TypePredicateNode).parameterName === entityName
63336334
) {
63346335
// Typeof value
63356336
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
@@ -8672,6 +8673,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
86728673
const meaning = getMeaningOfEntityNameReference(node);
86738674
const sym = resolveEntityName(leftmost, meaning, /*ignoreErrors*/ true, /*dontResolveAlias*/ true);
86748675
if (sym) {
8676+
// If a parameter is resolvable in the current context it is also visible, so no need to go to symbol accesibility
8677+
if (
8678+
sym.flags & SymbolFlags.FunctionScopedVariable
8679+
&& sym.valueDeclaration
8680+
) {
8681+
if (isParameterDeclaration(sym.valueDeclaration)) {
8682+
return { introducesError, node: attachSymbolToLeftmostIdentifier(node) as T };
8683+
}
8684+
}
86758685
if (
86768686
!(sym.flags & SymbolFlags.TypeParameter) && // Type parameters are visible in the curent context if they are are resolvable
86778687
!isDeclarationName(node) &&

tests/baselines/reference/conditionallyDuplicateOverloadsCausedByOverloadResolution.types

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,24 @@ var out = foo((x, y) => {
2828
> : ^^^^^^^
2929
>foo : { (func: (x: string, y: string) => any): boolean; (func: (x: string, y: number) => any): string; }
3030
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31-
>(x, y) => { function bar(a: typeof x): void; function bar(b: typeof y): void; function bar() { } return bar;} : (x: string, y: string) => { (a: string): void; (b: string): void; }
32-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^
31+
>(x, y) => { function bar(a: typeof x): void; function bar(b: typeof y): void; function bar() { } return bar;} : (x: string, y: string) => { (a: typeof x): void; (b: typeof y): void; }
32+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^ ^^^ ^^^
3333
>x : string
3434
> : ^^^^^^
3535
>y : string
3636
> : ^^^^^^
3737

3838
function bar(a: typeof x): void;
39-
>bar : { (a: string): void; (b: string): void; }
40-
> : ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
39+
>bar : { (a: typeof x): void; (b: string): void; }
40+
> : ^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^
4141
>a : string
4242
> : ^^^^^^
4343
>x : string
4444
> : ^^^^^^
4545

4646
function bar(b: typeof y): void;
47-
>bar : { (a: string): void; (b: string): void; }
48-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^
47+
>bar : { (a: string): void; (b: typeof y): void; }
48+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^
4949
>b : string
5050
> : ^^^^^^
5151
>y : string
@@ -88,16 +88,16 @@ var out2 = foo2((x, y) => {
8888
> : ^^^^^^^
8989
>foo2 : { (func: (x: string, y: string) => any): boolean; (func: (x: string, y: number) => any): string; }
9090
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91-
>(x, y) => { var bar: { (a: typeof x): void; (b: typeof y): void; }; return bar;} : (x: string, y: string) => { (a: string): void; (b: string): void; }
92-
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^
91+
>(x, y) => { var bar: { (a: typeof x): void; (b: typeof y): void; }; return bar;} : (x: string, y: string) => { (a: typeof x): void; (b: typeof y): void; }
92+
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^^^^ ^^^ ^^^
9393
>x : string
9494
> : ^^^^^^
9595
>y : string
9696
> : ^^^^^^
9797

9898
var bar: {
99-
>bar : { (a: string): void; (b: string): void; }
100-
> : ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ^^^
99+
>bar : { (a: typeof x): void; (b: typeof y): void; }
100+
> : ^^^^^^ ^^^ ^^^^^^ ^^^ ^^^
101101

102102
(a: typeof x): void;
103103
>a : string

tests/baselines/reference/renamingDestructuredPropertyInFunctionType.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ interface I {
171171
declare function f1({ a: string }: O): void;
172172
declare const f2: ({ a: string }: O) => void;
173173
declare const f3: ({ a: string, b, c }: O) => void;
174-
declare const f4: ({ a: string }: O) => string;
175-
declare const f5: ({ a: string, b, c }: O) => string;
174+
declare const f4: ({ a: string }: O) => typeof string;
175+
declare const f5: ({ a: string, b, c }: O) => typeof string;
176176
declare const obj1: {
177177
method({ a: string }: O): void;
178178
};
179179
declare const obj2: {
180-
method({ a: string }: O): string;
180+
method({ a: string }: O): typeof string;
181181
};
182182
declare function f6({ a: string }: O): void;
183183
declare const f7: ({ a: string, b, c }: O) => void;

tests/baselines/reference/renamingDestructuredPropertyInFunctionType.types

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ const f3 = ({ a: string, b, c }: O) => { };
325325
> : ^^^^^^
326326

327327
const f4 = function({ a: string }: O): typeof string { return string; };
328-
>f4 : ({ a: string }: O) => string
329-
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
330-
>function({ a: string }: O): typeof string { return string; } : ({ a: string }: O) => string
331-
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
328+
>f4 : ({ a: string }: O) => typeof string
329+
> : ^^^^^^^^^^^^^^^^ ^^^^^
330+
>function({ a: string }: O): typeof string { return string; } : ({ a: string }: O) => typeof string
331+
> : ^^^^^^^^^^^^^^^^ ^^^^^
332332
>a : any
333333
> : ^^^
334334
>string : string
@@ -339,10 +339,10 @@ const f4 = function({ a: string }: O): typeof string { return string; };
339339
> : ^^^^^^
340340

341341
const f5 = ({ a: string, b, c }: O): typeof string => '';
342-
>f5 : ({ a: string, b, c }: O) => string
343-
> : ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
344-
>({ a: string, b, c }: O): typeof string => '' : ({ a: string, b, c }: O) => string
345-
> : ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
342+
>f5 : ({ a: string, b, c }: O) => typeof string
343+
> : ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
344+
>({ a: string, b, c }: O): typeof string => '' : ({ a: string, b, c }: O) => typeof string
345+
> : ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^
346346
>a : any
347347
> : ^^^
348348
>string : string
@@ -372,14 +372,14 @@ const obj1 = {
372372

373373
};
374374
const obj2 = {
375-
>obj2 : { method({ a: string }: O): string; }
376-
> : ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
377-
>{ method({ a: string }: O): typeof string { return string; }} : { method({ a: string }: O): string; }
378-
> : ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^
375+
>obj2 : { method({ a: string }: O): typeof string; }
376+
> : ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^
377+
>{ method({ a: string }: O): typeof string { return string; }} : { method({ a: string }: O): typeof string; }
378+
> : ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ ^^^
379379

380380
method({ a: string }: O): typeof string { return string; }
381-
>method : ({ a: string }: O) => string
382-
> : ^^^^^^^^^^^^^^^^ ^^^^^^^^^^^
381+
>method : ({ a: string }: O) => typeof string
382+
> : ^^^^^^^^^^^^^^^^ ^^^^^
383383
>a : any
384384
> : ^^^
385385
>string : string

tests/baselines/reference/subtypingWithCallSignatures.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module CallSignature {
66
> : ^^^^^^^^^^^^^^^^^^^^
77

88
declare function foo1(cb: (x: number) => void): typeof cb;
9-
>foo1 : { (cb: (x: number) => void): (x: number) => void; (cb: any): any; }
10-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
9+
>foo1 : { (cb: (x: number) => void): typeof cb; (cb: any): any; }
10+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
1111
>cb : (x: number) => void
1212
> : ^^^^ ^^^^^
1313
>x : number
@@ -49,8 +49,8 @@ module CallSignature {
4949
> : ^^
5050

5151
declare function foo2(cb: (x: number, y: number) => void): typeof cb;
52-
>foo2 : { (cb: (x: number, y: number) => void): (x: number, y: number) => void; (cb: any): any; }
53-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
52+
>foo2 : { (cb: (x: number, y: number) => void): typeof cb; (cb: any): any; }
53+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
5454
>cb : (x: number, y: number) => void
5555
> : ^^^^ ^^^^^ ^^^^^
5656
>x : number

tests/baselines/reference/subtypingWithCallSignatures3.types

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ module Errors {
3939
> : ^^^^^^
4040

4141
declare function foo2(a2: (x: number) => string[]): typeof a2;
42-
>foo2 : { (a2: (x: number) => string[]): (x: number) => string[]; (a2: any): any; }
43-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
42+
>foo2 : { (a2: (x: number) => string[]): typeof a2; (a2: any): any; }
43+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
4444
>a2 : (x: number) => string[]
4545
> : ^^^^ ^^^^^
4646
>x : number
@@ -54,8 +54,8 @@ module Errors {
5454
>a2 : any
5555

5656
declare function foo7(a2: (x: (arg: Base) => Derived) => (r: Base) => Derived2): typeof a2;
57-
>foo7 : { (a2: (x: (arg: Base) => Derived) => (r: Base) => Derived2): (x: (arg: Base) => Derived) => (r: Base) => Derived2; (a2: any): any; }
58-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
57+
>foo7 : { (a2: (x: (arg: Base) => Derived) => (r: Base) => Derived2): typeof a2; (a2: any): any; }
58+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
5959
>a2 : (x: (arg: Base) => Derived) => (r: Base) => Derived2
6060
> : ^^^^ ^^^^^
6161
>x : (arg: Base) => Derived
@@ -73,8 +73,8 @@ module Errors {
7373
>a2 : any
7474

7575
declare function foo8(a2: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): typeof a2;
76-
>foo8 : { (a2: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; (a2: any): any; }
77-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
76+
>foo8 : { (a2: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived): typeof a2; (a2: any): any; }
77+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
7878
>a2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived
7979
> : ^^^^ ^^^^^ ^^^^^
8080
>x : (arg: Base) => Derived
@@ -96,8 +96,8 @@ module Errors {
9696
>a2 : any
9797

9898
declare function foo10(a2: (...x: Base[]) => Base): typeof a2;
99-
>foo10 : { (a2: (...x: Base[]) => Base): (...x: Base[]) => Base; (a2: any): any; }
100-
> : ^^^^^^^ ^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
99+
>foo10 : { (a2: (...x: Base[]) => Base): typeof a2; (a2: any): any; }
100+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
101101
>a2 : (...x: Base[]) => Base
102102
> : ^^^^^^^ ^^^^^
103103
>x : Base[]
@@ -111,8 +111,8 @@ module Errors {
111111
>a2 : any
112112

113113
declare function foo11(a2: (x: { foo: string }, y: { foo: string; bar: string }) => Base): typeof a2;
114-
>foo11 : { (a2: (x: { foo: string; }, y: { foo: string; bar: string; }) => Base): (x: { foo: string; }, y: { foo: string; bar: string; }) => Base; (a2: any): any; }
115-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
114+
>foo11 : { (a2: (x: { foo: string; }, y: { foo: string; bar: string; }) => Base): typeof a2; (a2: any): any; }
115+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
116116
>a2 : (x: { foo: string; }, y: { foo: string; bar: string; }) => Base
117117
> : ^^^^ ^^^^^ ^^^^^
118118
>x : { foo: string; }
@@ -134,8 +134,8 @@ module Errors {
134134
>a2 : any
135135

136136
declare function foo12(a2: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>): typeof a2;
137-
>foo12 : { (a2: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>): (x: Array<Base>, y: Array<Derived2>) => Array<Derived>; (a2: any): any; }
138-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
137+
>foo12 : { (a2: (x: Array<Base>, y: Array<Derived2>) => Array<Derived>): typeof a2; (a2: any): any; }
138+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
139139
>a2 : (x: Array<Base>, y: Array<Derived2>) => Array<Derived>
140140
> : ^^^^ ^^^^^ ^^^^^
141141
>x : Base[]
@@ -151,8 +151,8 @@ module Errors {
151151
>a2 : any
152152

153153
declare function foo15(a2: (x: { a: string; b: number }) => number): typeof a2;
154-
>foo15 : { (a2: (x: { a: string; b: number; }) => number): (x: { a: string; b: number; }) => number; (a2: any): any; }
155-
> : ^^^^^^^ ^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
154+
>foo15 : { (a2: (x: { a: string; b: number; }) => number): typeof a2; (a2: any): any; }
155+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
156156
>a2 : (x: { a: string; b: number; }) => number
157157
> : ^^^^ ^^^^^
158158
>x : { a: string; b: number; }
@@ -170,8 +170,8 @@ module Errors {
170170
>a2 : any
171171

172172
declare function foo16(a2: {
173-
>foo16 : { (a2: { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }): { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }; (a2: any): any; }
174-
> : ^^^^^^^ ^^^^^^^^^ ^^^ ^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^
173+
>foo16 : { (a2: { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }): typeof a2; (a2: any): any; }
174+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
175175
>a2 : { (x: { (a: number): number; (a?: number): number; }): number[]; (x: { (a: boolean): boolean; (a?: boolean): boolean; }): boolean[]; }
176176
> : ^^^^^^ ^^^ ^^^^^^ ^^^ ^^^
177177

@@ -212,8 +212,8 @@ module Errors {
212212
>a2 : any
213213

214214
declare function foo17(a2: {
215-
>foo17 : { (a2: { (x: { <T extends Derived>(a: T): T; <T extends Base>(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; }): { (x: { <T extends Derived>(a: T): T; <T extends Base>(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; }; (a2: any): any; }
216-
> : ^^^^^^^ ^^^^^^^^^ ^^^ ^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^^^^
215+
>foo17 : { (a2: { (x: { <T extends Derived>(a: T): T; <T extends Base>(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; }): typeof a2; (a2: any): any; }
216+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
217217
>a2 : { (x: { <T extends Derived>(a: T): T; <T extends Base>(a: T): T; }): any[]; (x: { <T extends Derived2>(a: T): T; <T extends Base>(a: T): T; }): any[]; }
218218
> : ^^^^^^ ^^^ ^^^^^^ ^^^ ^^^
219219

@@ -748,8 +748,8 @@ module WithGenericSignaturesInBaseType {
748748
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
749749

750750
declare function foo2(a2: <T>(x: T) => T[]): typeof a2;
751-
>foo2 : { (a2: <T>(x: T) => T[]): <T>(x: T) => T[]; (a2: any): any; }
752-
> : ^^^^^^^ ^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
751+
>foo2 : { (a2: <T>(x: T) => T[]): typeof a2; (a2: any): any; }
752+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
753753
>a2 : <T>(x: T) => T[]
754754
> : ^ ^^^^^ ^^^^^
755755
>x : T
@@ -783,8 +783,8 @@ module WithGenericSignaturesInBaseType {
783783
> : ^^^^^^^^^^^^^^^^^^^^^
784784

785785
declare function foo3(a2: <T>(x: T) => string[]): typeof a2;
786-
>foo3 : { (a2: <T>(x: T) => string[]): <T>(x: T) => string[]; (a2: any): any; }
787-
> : ^^^^^^^ ^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
786+
>foo3 : { (a2: <T>(x: T) => string[]): typeof a2; (a2: any): any; }
787+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
788788
>a2 : <T>(x: T) => string[]
789789
> : ^ ^^^^^ ^^^^^
790790
>x : T

tests/baselines/reference/subtypingWithConstructSignatures.types

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ module ConstructSignature {
66
> : ^^^^^^^^^^^^^^^^^^^^^^^^^
77

88
declare function foo1(cb: new (x: number) => void): typeof cb;
9-
>foo1 : { (cb: new (x: number) => void): new (x: number) => void; (cb: any): any; }
10-
> : ^^^^^^^ ^^^^^^^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
9+
>foo1 : { (cb: new (x: number) => void): typeof cb; (cb: any): any; }
10+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
1111
>cb : new (x: number) => void
1212
> : ^^^^^^^^ ^^^^^
1313
>x : number
@@ -53,8 +53,8 @@ module ConstructSignature {
5353
> : ^^^^^^^^^^^^^^^^^^^^^^^
5454

5555
declare function foo2(cb: new (x: number, y: number) => void): typeof cb;
56-
>foo2 : { (cb: new (x: number, y: number) => void): new (x: number, y: number) => void; (cb: any): any; }
57-
> : ^^^^^^^ ^^^^^^^^^^^ ^^^^^ ^^^^^ ^^^^^^^^^^^^^^^^^^^
56+
>foo2 : { (cb: new (x: number, y: number) => void): typeof cb; (cb: any): any; }
57+
> : ^^^^^^^ ^^^ ^^^^^^^^^^^^^^^^^^^
5858
>cb : new (x: number, y: number) => void
5959
> : ^^^^^^^^ ^^^^^ ^^^^^
6060
>x : number

0 commit comments

Comments
 (0)