-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix crash when serializing the return type of a generic call to Array…
….prototype.flat (#38904) (#39079) * Add declaration emit error and checking for circularly referential unions produced by recursive conditionals * Allow indexed accesses to produce alias symbols on types * Add test that still triggers the declaration emit error * Fix spelling
- Loading branch information
Showing
47 changed files
with
503 additions
and
222 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
21 changes: 21 additions & 0 deletions
21
tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.errors.txt
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,21 @@ | ||
tests/cases/compiler/arrayFakeFlatNoCrashInferenceDeclarations.ts(13,10): error TS5088: The inferred type of 'foo' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary. | ||
|
||
|
||
==== tests/cases/compiler/arrayFakeFlatNoCrashInferenceDeclarations.ts (1 errors) ==== | ||
type BadFlatArray<Arr, Depth extends number> = {obj: { | ||
"done": Arr, | ||
"recur": Arr extends ReadonlyArray<infer InnerArr> | ||
? BadFlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]> | ||
: Arr | ||
}[Depth extends -1 ? "done" : "recur"]}["obj"]; | ||
|
||
declare function flat<A, D extends number = 1>( | ||
arr: A, | ||
depth?: D | ||
): BadFlatArray<A, D>[] | ||
|
||
function foo<T>(arr: T[], depth: number) { | ||
~~~ | ||
!!! error TS5088: The inferred type of 'foo' references a type with a cyclic structure which cannot be trivially serialized. A type annotation is necessary. | ||
return flat(arr, depth); | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.js
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,22 @@ | ||
//// [arrayFakeFlatNoCrashInferenceDeclarations.ts] | ||
type BadFlatArray<Arr, Depth extends number> = {obj: { | ||
"done": Arr, | ||
"recur": Arr extends ReadonlyArray<infer InnerArr> | ||
? BadFlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]> | ||
: Arr | ||
}[Depth extends -1 ? "done" : "recur"]}["obj"]; | ||
|
||
declare function flat<A, D extends number = 1>( | ||
arr: A, | ||
depth?: D | ||
): BadFlatArray<A, D>[] | ||
|
||
function foo<T>(arr: T[], depth: number) { | ||
return flat(arr, depth); | ||
} | ||
|
||
//// [arrayFakeFlatNoCrashInferenceDeclarations.js] | ||
"use strict"; | ||
function foo(arr, depth) { | ||
return flat(arr, depth); | ||
} |
58 changes: 58 additions & 0 deletions
58
tests/baselines/reference/arrayFakeFlatNoCrashInferenceDeclarations.symbols
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,58 @@ | ||
=== tests/cases/compiler/arrayFakeFlatNoCrashInferenceDeclarations.ts === | ||
type BadFlatArray<Arr, Depth extends number> = {obj: { | ||
>BadFlatArray : Symbol(BadFlatArray, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 0)) | ||
>Arr : Symbol(Arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 18)) | ||
>Depth : Symbol(Depth, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 22)) | ||
>obj : Symbol(obj, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 48)) | ||
|
||
"done": Arr, | ||
>"done" : Symbol("done", Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 54)) | ||
>Arr : Symbol(Arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 18)) | ||
|
||
"recur": Arr extends ReadonlyArray<infer InnerArr> | ||
>"recur" : Symbol("recur", Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 1, 16)) | ||
>Arr : Symbol(Arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 18)) | ||
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --)) | ||
>InnerArr : Symbol(InnerArr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 2, 44)) | ||
|
||
? BadFlatArray<InnerArr, [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20][Depth]> | ||
>BadFlatArray : Symbol(BadFlatArray, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 0)) | ||
>InnerArr : Symbol(InnerArr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 2, 44)) | ||
>Depth : Symbol(Depth, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 22)) | ||
|
||
: Arr | ||
>Arr : Symbol(Arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 18)) | ||
|
||
}[Depth extends -1 ? "done" : "recur"]}["obj"]; | ||
>Depth : Symbol(Depth, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 22)) | ||
|
||
declare function flat<A, D extends number = 1>( | ||
>flat : Symbol(flat, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 5, 47)) | ||
>A : Symbol(A, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 22)) | ||
>D : Symbol(D, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 24)) | ||
|
||
arr: A, | ||
>arr : Symbol(arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 47)) | ||
>A : Symbol(A, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 22)) | ||
|
||
depth?: D | ||
>depth : Symbol(depth, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 8, 11)) | ||
>D : Symbol(D, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 24)) | ||
|
||
): BadFlatArray<A, D>[] | ||
>BadFlatArray : Symbol(BadFlatArray, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 0, 0)) | ||
>A : Symbol(A, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 22)) | ||
>D : Symbol(D, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 7, 24)) | ||
|
||
function foo<T>(arr: T[], depth: number) { | ||
>foo : Symbol(foo, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 10, 23)) | ||
>T : Symbol(T, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 12, 13)) | ||
>arr : Symbol(arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 12, 16)) | ||
>T : Symbol(T, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 12, 13)) | ||
>depth : Symbol(depth, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 12, 25)) | ||
|
||
return flat(arr, depth); | ||
>flat : Symbol(flat, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 5, 47)) | ||
>arr : Symbol(arr, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 12, 16)) | ||
>depth : Symbol(depth, Decl(arrayFakeFlatNoCrashInferenceDeclarations.ts, 12, 25)) | ||
} |
Oops, something went wrong.