-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ts/analyzer): Fix variance issue (#135)
**Description:** - Allow assignment of void in function return values. - Fix variance handling. **Related issue:** - Closes #136.
- Loading branch information
Showing
16 changed files
with
170 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...file_analyzer/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.swc-stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.ts:6:12 | ||
| | ||
6 | return r; | ||
| ^ | ||
| | ||
= note: (x: T) => T | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.ts:10:15 | ||
| | ||
10 | var r1b = foo((x) => 1, (x) => ''); // {} => {} | ||
| ^^^^^^^^ | ||
| | ||
= note: (x: any) => 1 | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.ts:10:25 | ||
| | ||
10 | var r1b = foo((x) => 1, (x) => ''); // {} => {} | ||
| ^^^^^^^^^ | ||
| | ||
= note: (x: any) => '' | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.ts:10:11 | ||
| | ||
10 | var r1b = foo((x) => 1, (x) => ''); // {} => {} | ||
| ^^^ | ||
| | ||
= note: <T>(a: (x: T) => T, b: (x: T) => T) => (x: T) => T | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.ts:10:11 | ||
| | ||
10 | var r1b = foo((x) => 1, (x) => ''); // {} => {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: (x: unknown) => unknown | ||
|
12 changes: 12 additions & 0 deletions
12
.../stc_ts_file_analyzer/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, | ||
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. | ||
|
||
function foo<T>(a: (x: T) => T, b: (x: T) => T) { | ||
var r: (x: T) => T; | ||
return r; | ||
} | ||
|
||
//var r1 = foo((x: number) => 1, (x: string) => ''); // error | ||
var r1b = foo((x) => 1, (x) => ''); // {} => {} | ||
|
||
export { } |
40 changes: 40 additions & 0 deletions
40
...file_analyzer/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.swc-stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.ts:6:12 | ||
| | ||
6 | return r; | ||
| ^ | ||
| | ||
= note: (x: T) => T | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.ts:10:14 | ||
| | ||
10 | var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: (x: Object) => null | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.ts:10:35 | ||
| | ||
10 | var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: (x: string) => '' | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.ts:10:10 | ||
| | ||
10 | var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object | ||
| ^^^ | ||
| | ||
= note: <T>(a: (x: T) => T, b: (x: T) => T) => (x: T) => T | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.ts:10:10 | ||
| | ||
10 | var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: (x: Object) => Object | ||
|
12 changes: 12 additions & 0 deletions
12
.../stc_ts_file_analyzer/tests/pass/exprs/call/genericCallWithGenericSignatureArguments/2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// When a function expression is inferentially typed (section 4.9.3) and a type assigned to a parameter in that expression references type parameters for which inferences are being made, | ||
// the corresponding inferred type arguments to become fixed and no further candidate inferences are made for them. | ||
|
||
function foo<T>(a: (x: T) => T, b: (x: T) => T) { | ||
var r: (x: T) => T; | ||
return r; | ||
} | ||
|
||
//var r1 = foo((x: number) => 1, (x: string) => ''); // error | ||
var r2 = foo((x: Object) => null, (x: string) => ''); // Object => Object | ||
|
||
export { } |
19 changes: 19 additions & 0 deletions
19
...s/stc_ts_file_analyzer/tests/pass/types/union/unionAndIntersectionInference3/1.swc-stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
warning: Type | ||
--> $DIR/tests/pass/types/union/unionAndIntersectionInference3/1.ts:7:9 | ||
| | ||
7 | throw com; | ||
| ^^^ | ||
| | ||
= note: () => (Iterator<S, U, R> | AsyncIterator<S, U, R>) | ||
|
||
warning: Type | ||
--> $DIR/tests/pass/types/union/unionAndIntersectionInference3/1.ts:6:98 | ||
| | ||
6 | export const g: <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U> = async <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>): Promise<U> => { | ||
| __________________________________________________________________________________________________^ | ||
7 | | throw com; | ||
8 | | }; | ||
| |_^ | ||
| | ||
= note: <U, R, S>(com: () => (Iterator<S, U, R> | AsyncIterator<S, U, R>)) => Promise<U> | ||
|
9 changes: 9 additions & 0 deletions
9
crates/stc_ts_file_analyzer/tests/pass/types/union/unionAndIntersectionInference3/1.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// @strict: true | ||
// @target: esnext | ||
|
||
// Repros from #32247 | ||
|
||
export const g: <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U> = async <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>): Promise<U> => { | ||
throw com; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.