-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Instantiate earlier inferred constraints in conditional types #57362
Merged
DanielRosenwasser
merged 1 commit into
microsoft:main
from
Andarist:fully-instantiated-constraints-for-infer-type-params
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
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.
This PR - in its current form - removes the context of those fresh params.
They were introduced in this PR to address a type parameter leak. From what I understand, the leak was caused by non-instantiated constraints of infer type parameters, and those fresh params were introduced to "wire up" the
mapper
so it would partake in the instantiation of those constraints. Those instantiations are made usingcontext.nonFixingMapper
so I figured out that maybe this can be simplified by combining that with themapper
.The problem with
maybeCloneTypeParameter
that was used to create thosefreshParams
is that the check inside it is non-exhaustive:When it comes to the added test case, this check doesn't cover
Klass<V>
- that's neither of the tested things. (when the inferredKlass<number>
gets checked against that constraint it fails the assignability check and the inferred result gets replaced by the constraint which in turn is instantiated by thecombinedMapper
)So the alternative fix would be to extend this check to cover more situations. That can't be done exhaustively and cheaply. The closest check to that is
couldContainTypeVariables
and that's not supposed to be used in situations like this, it's just an optimization.So given the fact above, one extra alternative solution comes to mind...
freshParams
could always be created. I verified that it would fix the issue and that it wouldn't break any existing case.