Repository navigation
Restore the enclosing variance diagnostic context - #65466
Open
Jake Bailey (jakebailey) wants to merge 1 commit into
Open
Jake Bailey (jakebailey) wants to merge 1 commit into
Jake Bailey (jakebailey) wants to merge 1 commit into
Conversation
Variance annotation checking temporarily selects the parameter used to format marker types. Preserve the previous selection instead of leaving the checked parameter installed after the annotation check. Exercise consecutive annotations and a deferred ordinary assignment without exposing checker internals.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The new test does not exercise restoration of varianceTypeParameter, so its expected diagnostics cannot distinguish the fix from the previous behavior.
1 open issue
What changed in this PR
This PR fixes variance-diagnostic state handling in the native TypeScript checker by restoring the enclosing context after checking a variance annotation.
Changes:
- Save the previous checker context rather than the current type parameter.
- Add a compiler test covering invalid variance annotations and an incompatible assignment, with diagnostic, emit, type, and symbol baselines.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/varianceAnnotationDiagnosticState.ts |
Adds variance-annotation and assignment diagnostic cases. |
tsc/testdata/baselines/reference/compiler/varianceAnnotationDiagnosticState.types |
Records expected type information. |
tsc/testdata/baselines/reference/compiler/varianceAnnotationDiagnosticState.symbols |
Records expected symbol bindings. |
tsc/testdata/baselines/reference/compiler/varianceAnnotationDiagnosticState.js |
Records JavaScript and declaration output. |
tsc/testdata/baselines/reference/compiler/varianceAnnotationDiagnosticState.errors.txt |
Records two variance errors and an assignment error. |
tsc/internal/checker/checker.go |
Corrects saving and restoration of the variance diagnostic context. |
Review effort: Balanced
| declare let strings: Container<string>; | ||
| declare let numbers: Container<number>; | ||
| const assign = () => { | ||
| strings = numbers; |
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.

This was found through other means, but I also found this in #65064 too.