Repository navigation
Finalize evolving array types before narrowing in switch clauses - #64814
Open
Mateusz Burzyński (Andarist) wants to merge 2 commits into
Open
Mateusz Burzyński (Andarist) wants to merge 2 commits into
Mateusz Burzyński (Andarist) wants to merge 2 commits into
Conversation
| expr := ast.SkipParentheses(data.SwitchStatement.Expression()) | ||
| flowType := c.getTypeAtFlowNode(f, flow.Antecedent) | ||
| t := flowType.t | ||
| nonEvolvingType := c.finalizeEvolvingArrayType(flowType.t) |
Contributor
Author
There was a problem hiding this comment.
this just matches the preestablished pattern used by other narrowing~ functions like getTypeAtFlowCondition, getTypeAtFlowCall and co.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The preservation test does not detect premature finalization because any[] remains assignable to string[].
1 open finding
What changed in this PR
Prevents compiler crashes when switch narrowing encounters evolving array types.
Changes:
- Finalizes evolving arrays before switch narrowing.
- Preserves evolving flow types when narrowing is unchanged.
- Adds compiler regression coverage and baselines.
| File | Description |
|---|---|
tsc/internal/checker/flow.go |
Safely handles evolving arrays during switch narrowing. |
tsc/testdata/tests/cases/compiler/narrowSwitchOnEvolvingArrayNoCrash1.ts |
Adds regression scenarios. |
tsc/testdata/baselines/reference/compiler/narrowSwitchOnEvolvingArrayNoCrash1.types |
Records inferred types. |
tsc/testdata/baselines/reference/compiler/narrowSwitchOnEvolvingArrayNoCrash1.symbols |
Records symbols. |
tsc/testdata/baselines/reference/compiler/narrowSwitchOnEvolvingArrayNoCrash1.errors.txt |
Records diagnostics. |
🧠 Review effort: Balanced
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

fixes #64813