Skip to content

Restore the enclosing variance diagnostic context - #65466

Merged
Jake Bailey (jakebailey) merged 2 commits into
microsoft:mainfrom
jakebailey:compiler-fixes/variance-state
Nov 14, 2026
Merged

Jake Bailey (jakebailey) merged 2 commits 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

Consecutive annotations set their own diagnostic context, and ordinary
assignments do not reference the variance marker types. The case produces
the same diagnostics with the incorrect save expression, so it cannot
serve as a regression for context restoration.

Remove the case and its baselines rather than asserting private checker
state.

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 variance-state restoration fix lacks a regression test verifying the diagnostic context and correct sub-/super- marker names after a variance check returns.

1 open issue
1 resolved since last review

Review effort: Balanced

Comment thread tsc/internal/checker/checker.go Resolved
@github-project-automation github-project-automation Bot moved this from Not started to Needs merge in PR Backlog Nov 13, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Nov 13, 2026
Merged via the queue into microsoft:main with commit acd44c3 Nov 14, 2026
34 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the compiler-fixes/variance-state branch November 14, 2026 00:03
@github-project-automation github-project-automation Bot moved this from Needs merge to Done in PR Backlog Nov 14, 2026
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: Done

Development

Successfully merging this pull request may close these issues.

4 participants