-
Notifications
You must be signed in to change notification settings - Fork 12.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bailout early from
isFunctionObjectType
for evolving arrays (#58049)
Co-authored-by: Jake Bailey <[email protected]>
- Loading branch information
1 parent
74cefa8
commit 1da9630
Showing
5 changed files
with
150 additions
and
0 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
25 changes: 25 additions & 0 deletions
25
.../baselines/reference/narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.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,25 @@ | ||
narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts(1,5): error TS7034: Variable 'foo' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts(5,5): error TS7005: Variable 'foo' implicitly has an 'any[]' type. | ||
|
||
|
||
==== narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts (2 errors) ==== | ||
let foo = []; | ||
~~~ | ||
!!! error TS7034: Variable 'foo' implicitly has type 'any[]' in some locations where its type cannot be determined. | ||
|
||
switch (foo?.length) { | ||
case 1: | ||
foo[0]; | ||
~~~ | ||
!!! error TS7005: Variable 'foo' implicitly has an 'any[]' type. | ||
} | ||
|
||
let bar = []; | ||
|
||
switch (bar?.length) { | ||
case 1: { | ||
bar.push("baz"); | ||
const arr: string[] = bar; | ||
} | ||
} | ||
|
36 changes: 36 additions & 0 deletions
36
tests/baselines/reference/narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.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,36 @@ | ||
//// [tests/cases/compiler/narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts] //// | ||
|
||
=== narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts === | ||
let foo = []; | ||
>foo : Symbol(foo, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 0, 3)) | ||
|
||
switch (foo?.length) { | ||
>foo?.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) | ||
>foo : Symbol(foo, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 0, 3)) | ||
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) | ||
|
||
case 1: | ||
foo[0]; | ||
>foo : Symbol(foo, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 0, 3)) | ||
} | ||
|
||
let bar = []; | ||
>bar : Symbol(bar, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 7, 3)) | ||
|
||
switch (bar?.length) { | ||
>bar?.length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) | ||
>bar : Symbol(bar, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 7, 3)) | ||
>length : Symbol(Array.length, Decl(lib.es5.d.ts, --, --)) | ||
|
||
case 1: { | ||
bar.push("baz"); | ||
>bar.push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
>bar : Symbol(bar, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 7, 3)) | ||
>push : Symbol(Array.push, Decl(lib.es5.d.ts, --, --)) | ||
|
||
const arr: string[] = bar; | ||
>arr : Symbol(arr, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 12, 9)) | ||
>bar : Symbol(bar, Decl(narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts, 7, 3)) | ||
} | ||
} | ||
|
68 changes: 68 additions & 0 deletions
68
tests/baselines/reference/narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.types
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,68 @@ | ||
//// [tests/cases/compiler/narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts] //// | ||
|
||
=== narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.ts === | ||
let foo = []; | ||
>foo : any[] | ||
> : ^^^^^ | ||
>[] : never[] | ||
> : ^^^^^^^ | ||
|
||
switch (foo?.length) { | ||
>foo?.length : number | ||
> : ^^^^^^ | ||
>foo : any[] | ||
> : ^^^^^ | ||
>length : number | ||
> : ^^^^^^ | ||
|
||
case 1: | ||
>1 : 1 | ||
> : ^ | ||
|
||
foo[0]; | ||
>foo[0] : any | ||
> : ^^^ | ||
>foo : any[] | ||
> : ^^^^^ | ||
>0 : 0 | ||
> : ^ | ||
} | ||
|
||
let bar = []; | ||
>bar : any[] | ||
> : ^^^^^ | ||
>[] : never[] | ||
> : ^^^^^^^ | ||
|
||
switch (bar?.length) { | ||
>bar?.length : number | ||
> : ^^^^^^ | ||
>bar : any[] | ||
> : ^^^^^ | ||
>length : number | ||
> : ^^^^^^ | ||
|
||
case 1: { | ||
>1 : 1 | ||
> : ^ | ||
|
||
bar.push("baz"); | ||
>bar.push("baz") : number | ||
> : ^^^^^^ | ||
>bar.push : (...items: any[]) => number | ||
> : ^^^^ ^^^^^^^^^^^^ | ||
>bar : any[] | ||
> : ^^^^^ | ||
>push : (...items: any[]) => number | ||
> : ^^^^ ^^^^^^^^^^^^ | ||
>"baz" : "baz" | ||
> : ^^^^^ | ||
|
||
const arr: string[] = bar; | ||
>arr : string[] | ||
> : ^^^^^^^^ | ||
>bar : string[] | ||
> : ^^^^^^^^ | ||
} | ||
} | ||
|
18 changes: 18 additions & 0 deletions
18
tests/cases/compiler/narrowSwitchOptionalChainContainmentEvolvingArrayNoCrash1.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,18 @@ | ||
// @strict: true | ||
// @noEmit: true | ||
|
||
let foo = []; | ||
|
||
switch (foo?.length) { | ||
case 1: | ||
foo[0]; | ||
} | ||
|
||
let bar = []; | ||
|
||
switch (bar?.length) { | ||
case 1: { | ||
bar.push("baz"); | ||
const arr: string[] = bar; | ||
} | ||
} |