-
Notifications
You must be signed in to change notification settings - Fork 730
Port TypeScript PR #62604: Propagate variance reliability #1916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: RyanCavanaugh <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ports TypeScript PR #62604, which fixes variance reliability propagation in type argument comparison. The change ensures that when computing variance, the Unreliable flag is properly tracked through the type system to avoid incorrect type checking in complex generic scenarios.
Key Changes:
- Modified
typeArgumentsRelatedTofunction to propagate theVarianceFlags.Unreliableflag during variance computation - Restructured conditional logic to check for unreliable variance before performing covariant/contravariant/bivariant checks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM though did it did not include the test.
|
Waiting for microsoft/TypeScript#62701 to go into |
|
Updated this PR now that main has the test. I can't approve anymore, unfortunately. |
Fixes #1781
This PR ports the changes from microsoft/TypeScript#62604, which implements proper propagation of the
VarianceFlags.Unreliableflag during type argument comparison.Background
The TypeScript compiler computes variance information for generic type parameters to determine how types with different type arguments relate to each other. This variance can be:
T<A>is assignable toT<B>ifAis assignable toBT<A>is assignable toT<B>ifBis assignable toAT<A>is only assignable toT<B>ifAandBare identicalAdditionally, variance can be marked as Unreliable when the computation involves complex type relationships that may not provide fully trustworthy variance information.
The Problem
Previously, the
Unreliableflag computed during variance analysis was not being propagated when comparing type arguments. This could lead to incorrect type checking in edge cases involving complex generic types with mapped types, conditional types, or intersection types.The Fix
Modified the
typeArgumentsRelatedTofunction ininternal/checker/relater.goto propagate theUnreliablevariance flag:When we're computing variance and encounter a type parameter with the
Unreliableflag, we now instantiate the source type withreportUnreliableMapperto properly track and propagate this reliability information through subsequent type comparisons.Testing
All existing tests continue to pass. The original TypeScript PR includes a new test case (variancePropagation.ts), which will be automatically included once the submodule is updated after the upstream PR is merged.
Related
Note: The upstream PR is currently open and not yet merged. This port implements the final version of the change (which propagates only
Unreliable, notUnmeasurable, to avoid performance impacts).Original prompt
Note
Custom agent used: Strada to Corsa Port Expert
A Go and TypeScript expert who can easily figure out how to port PRs from one language to another
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.