Repository navigation
Fix assignment-target detection through type assertions - #64965
Open
Cheng (chengchuu) wants to merge 1 commit into
Open
Cheng (chengchuu) wants to merge 1 commit into
Cheng (chengchuu) wants to merge 1 commit 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 tests for ordinary and nested writes, uninitialized reads, compound assignments, const/readonly targets, and mutable-object casts. Existing scenarios are preserved with updated baselines.
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 and exited 2 before the fix. I reran it with a compiler built from
4a2cd92c47d744d003a81503982430914c677b0d: no diagnostics, exit 0.AI assistance: Copilot helped generate the regression tests. I reviewed the changes and will handle any review feedback or revisions myself.