Skip to content

Restore the enclosing variance diagnostic context - #65466

Open
Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/variance-state
Open

Jake Bailey (jakebailey) wants to merge 1 commit into
microsoft:mainfrom
jakebailey:compiler-fixes/variance-state

Conversation

@jakebailey

Copy link
Copy Markdown
Member

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

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.
Copilot AI balanced review requested due to automatic review settings November 13, 2026 04:42
@github-project-automation github-project-automation Bot moved this to Not started in PR Backlog Nov 13, 2026
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Nov 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants