Repository navigation
Fix assignment-target detection through type assertions - #64965
Open
Cheng (chengchuu) wants to merge 2 commits into
Open
Cheng (chengchuu) wants to merge 2 commits into
Cheng (chengchuu) wants to merge 2 commits into
Conversation
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.
Summary
Fixes #62127
Fix false TS2454 ("used before being assigned") diagnostics on writes through
asand angle-bracket assertions in the Go compiler. This follows #62128, including the const and readonly assignment coverage requested by Jake Bailey and Ryan Cavanaugh. The following code now compiles without errors:Assignment checks now apply through assertions. Previously accepted writes to constants, readonly properties, class bindings, and restricted generic indexes can therefore report errors. JavaScript emission is unchanged.
Added regression coverage for assertion-wrapped writes, reads, compound assignments, and assignment restrictions.
Read-after-assignment flow analysis remains unchanged: a subsequent read can still report TS2454 after an assertion-wrapped assignment.
Validation
I manually ran the following focused tests from the repository root on macOS ARM64. All passed:
The standalone reproduction reported TS2454 before the fix and compiled without diagnostics with the patched compiler.
AI assistance: Copilot helped generate the regression tests. I reviewed the changes and will handle any review feedback or revisions myself.