Skip to content

Commit 183072b

Browse files
committed
Revert microsoft#26762, microsoft#26726, and microsoft#26317 in preparation for a clean PR fixing all the issues.
1 parent acc3502 commit 183072b

6 files changed

+55
-34
lines changed

src/compiler/checker.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -1211,23 +1211,17 @@ namespace ts {
12111211
// local types not visible outside the function body
12121212
: false;
12131213
}
1214-
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.Variable) {
1215-
// expression inside parameter will lookup as normal variable scope when targeting es2015+
1216-
if (compilerOptions.target && compilerOptions.target >= ScriptTarget.ES2015 && isParameter(lastLocation) && !isParameterPropertyDeclaration(lastLocation) && result.valueDeclaration.pos > lastLocation.end) {
1217-
useResult = false;
1218-
}
1219-
else if (result.flags & SymbolFlags.FunctionScopedVariable) {
1220-
// parameters are visible only inside function body, parameter list and return type
1221-
// technically for parameter list case here we might mix parameters and variables declared in function,
1222-
// however it is detected separately when checking initializers of parameters
1223-
// to make sure that they reference no variables declared after them.
1224-
useResult =
1214+
if (meaning & SymbolFlags.Value && result.flags & SymbolFlags.FunctionScopedVariable) {
1215+
// parameters are visible only inside function body, parameter list and return type
1216+
// technically for parameter list case here we might mix parameters and variables declared in function,
1217+
// however it is detected separately when checking initializers of parameters
1218+
// to make sure that they reference no variables declared after them.
1219+
useResult =
12251220
lastLocation.kind === SyntaxKind.Parameter ||
12261221
(
12271222
lastLocation === (<FunctionLikeDeclaration>location).type &&
12281223
!!findAncestor(result.valueDeclaration, isParameter)
12291224
);
1230-
}
12311225
}
12321226
}
12331227
else if (location.kind === SyntaxKind.ConditionalType) {

tests/baselines/reference/genericRestParameters1.errors.txt

+8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
tests/cases/conformance/types/rest/genericRestParameters1.ts(22,1): error TS2556: Expected 3 arguments, but got 1 or more.
22
tests/cases/conformance/types/rest/genericRestParameters1.ts(31,1): error TS2556: Expected 3 arguments, but got 1 or more.
33
tests/cases/conformance/types/rest/genericRestParameters1.ts(133,40): error TS2344: Type '(...args: T) => void' does not satisfy the constraint '(...args: any[]) => any'.
4+
Types of parameters 'args' and 'args' are incompatible.
5+
Type 'any[]' is not assignable to type 'T'.
46
tests/cases/conformance/types/rest/genericRestParameters1.ts(134,51): error TS2344: Type 'new (...args: T) => void' does not satisfy the constraint 'new (...args: any[]) => any'.
7+
Types of parameters 'args' and 'args' are incompatible.
8+
Type 'any[]' is not assignable to type 'T'.
59
tests/cases/conformance/types/rest/genericRestParameters1.ts(135,23): error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'.
610
Type 'Function' provides no match for the signature '(...args: any[]): any'.
711
tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS2322: Type '(a: never) => void' is not assignable to type '(...args: any[]) => void'.
@@ -149,9 +153,13 @@ tests/cases/conformance/types/rest/genericRestParameters1.ts(164,1): error TS232
149153
type T07<T extends any[]> = Parameters<(...args: T) => void>;
150154
~~~~~~~~~~~~~~~~~~~~
151155
!!! error TS2344: Type '(...args: T) => void' does not satisfy the constraint '(...args: any[]) => any'.
156+
!!! error TS2344: Types of parameters 'args' and 'args' are incompatible.
157+
!!! error TS2344: Type 'any[]' is not assignable to type 'T'.
152158
type T08<T extends any[]> = ConstructorParameters<new (...args: T) => void>;
153159
~~~~~~~~~~~~~~~~~~~~~~~~
154160
!!! error TS2344: Type 'new (...args: T) => void' does not satisfy the constraint 'new (...args: any[]) => any'.
161+
!!! error TS2344: Types of parameters 'args' and 'args' are incompatible.
162+
!!! error TS2344: Type 'any[]' is not assignable to type 'T'.
155163
type T09 = Parameters<Function>;
156164
~~~~~~~~
157165
!!! error TS2344: Type 'Function' does not satisfy the constraint '(...args: any[]) => any'.

tests/baselines/reference/genericRestParameters2.errors.txt

+6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
tests/cases/conformance/types/rest/genericRestParameters2.ts(71,40): error TS2344: Type '(x: string, ...args: T) => void' does not satisfy the constraint '(...args: any[]) => any'.
2+
Types of parameters 'x' and 'args' are incompatible.
3+
Type 'any[]' is not assignable to type '[string, ...any[]]'.
4+
Property '0' is missing in type 'any[]'.
25

36

47
==== tests/cases/conformance/types/rest/genericRestParameters2.ts (1 errors) ====
@@ -75,6 +78,9 @@ tests/cases/conformance/types/rest/genericRestParameters2.ts(71,40): error TS234
7578
type T05<T extends any[]> = Parameters<(x: string, ...args: T) => void>;
7679
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7780
!!! error TS2344: Type '(x: string, ...args: T) => void' does not satisfy the constraint '(...args: any[]) => any'.
81+
!!! error TS2344: Types of parameters 'x' and 'args' are incompatible.
82+
!!! error TS2344: Type 'any[]' is not assignable to type '[string, ...any[]]'.
83+
!!! error TS2344: Property '0' is missing in type 'any[]'.
7884
type T06 = T05<[number, ...boolean[]]>;
7985

8086
type P1<T extends Function> = T extends (head: infer A, ...tail: infer B) => any ? { head: A, tail: B } : any[];

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.errors.txt

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
1+
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(3,20): error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
2+
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(8,27): error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
3+
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(13,20): error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
14
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(21,18): error TS2372: Parameter 'a' cannot be referenced in its initializer.
25
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(25,22): error TS2372: Parameter 'async' cannot be referenced in its initializer.
6+
tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts(29,15): error TS2448: Block-scoped variable 'foo' used before its declaration.
37

48

5-
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts (2 errors) ====
9+
==== tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts (6 errors) ====
610
let foo: string = "";
711

812
function f1 (bar = foo) { // unexpected compiler error; works at runtime
13+
~~~
14+
!!! error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
915
var foo: number = 2;
1016
return bar; // returns 1
1117
}
1218

1319
function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at runtime
20+
~~~
21+
!!! error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
1422
var foo: number = 2;
1523
return bar(); // returns 1
1624
}
1725

1826
function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
27+
~~~
28+
!!! error TS2373: Initializer of parameter 'bar' cannot reference identifier 'foo' declared after it.
1929
return bar;
2030
}
2131

@@ -36,6 +46,9 @@ tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.t
3646
}
3747

3848
function f7({[foo]: bar}: any[]) {
49+
~~~
50+
!!! error TS2448: Block-scoped variable 'foo' used before its declaration.
51+
!!! related TS2728 tests/cases/conformance/functions/parameterInitializersForwardReferencing1_es6.ts:30:9: 'foo' is declared here.
3952
let foo: number = 2;
4053
}
4154

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.symbols

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ let foo: string = "";
55
function f1 (bar = foo) { // unexpected compiler error; works at runtime
66
>f1 : Symbol(f1, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 21))
77
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 2, 13))
8-
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
8+
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 3, 7))
99

1010
var foo: number = 2;
1111
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 3, 7))
@@ -18,7 +18,7 @@ function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at
1818
>f2 : Symbol(f2, Decl(parameterInitializersForwardReferencing1_es6.ts, 5, 1))
1919
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 7, 13))
2020
>baz : Symbol(baz, Decl(parameterInitializersForwardReferencing1_es6.ts, 7, 20))
21-
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
21+
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 8, 7))
2222
>baz : Symbol(baz, Decl(parameterInitializersForwardReferencing1_es6.ts, 7, 20))
2323

2424
var foo: number = 2;
@@ -31,7 +31,7 @@ function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at
3131
function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
3232
>f3 : Symbol(f3, Decl(parameterInitializersForwardReferencing1_es6.ts, 10, 1))
3333
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 12, 13))
34-
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
34+
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 12, 23))
3535
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 12, 23))
3636

3737
return bar;
@@ -68,7 +68,7 @@ function f6 (async = async) {
6868

6969
function f7({[foo]: bar}: any[]) {
7070
>f7 : Symbol(f7, Decl(parameterInitializersForwardReferencing1_es6.ts, 26, 1))
71-
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 0, 3))
71+
>foo : Symbol(foo, Decl(parameterInitializersForwardReferencing1_es6.ts, 29, 7))
7272
>bar : Symbol(bar, Decl(parameterInitializersForwardReferencing1_es6.ts, 28, 13))
7373

7474
let foo: number = 2;

tests/baselines/reference/parameterInitializersForwardReferencing1_es6.types

+17-17
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,44 @@ let foo: string = "";
44
>"" : ""
55

66
function f1 (bar = foo) { // unexpected compiler error; works at runtime
7-
>f1 : (bar?: string) => string
8-
>bar : string
9-
>foo : string
7+
>f1 : (bar?: number) => number
8+
>bar : number
9+
>foo : number
1010

1111
var foo: number = 2;
1212
>foo : number
1313
>2 : 2
1414

1515
return bar; // returns 1
16-
>bar : string
16+
>bar : number
1717
}
1818

1919
function f2 (bar = (baz = foo) => baz) { // unexpected compiler error; works at runtime
20-
>f2 : (bar?: (baz?: string) => string) => string
21-
>bar : (baz?: string) => string
22-
>(baz = foo) => baz : (baz?: string) => string
23-
>baz : string
24-
>foo : string
25-
>baz : string
20+
>f2 : (bar?: (baz?: number) => number) => number
21+
>bar : (baz?: number) => number
22+
>(baz = foo) => baz : (baz?: number) => number
23+
>baz : number
24+
>foo : number
25+
>baz : number
2626

2727
var foo: number = 2;
2828
>foo : number
2929
>2 : 2
3030

3131
return bar(); // returns 1
32-
>bar() : string
33-
>bar : (baz?: string) => string
32+
>bar() : number
33+
>bar : (baz?: number) => number
3434
}
3535

3636
function f3 (bar = foo, foo = 2) { // correct compiler error, error at runtime
37-
>f3 : (bar?: string, foo?: number) => string
38-
>bar : string
39-
>foo : string
37+
>f3 : (bar?: number, foo?: number) => number
38+
>bar : number
39+
>foo : number
4040
>foo : number
4141
>2 : 2
4242

4343
return bar;
44-
>bar : string
44+
>bar : number
4545
}
4646

4747
function f4 (foo, bar = foo) {
@@ -74,7 +74,7 @@ function f6 (async = async) {
7474

7575
function f7({[foo]: bar}: any[]) {
7676
>f7 : ({ [foo]: bar }: any[]) => void
77-
>foo : string
77+
>foo : number
7878
>bar : any
7979

8080
let foo: number = 2;

0 commit comments

Comments
 (0)