-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Fix type parameters upon subsequent visits to a parameter that caused fixing the first time #3787
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
assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper); | ||
} | ||
if (!node.type && !signature.resolvedReturnType) { | ||
if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) { |
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.
why you have to check mightFixTypeParameters
again?
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.
Good question. In this case, I noticed that we are passing the contextualMapper into getReturnTypeFromBody. That indicates to me that we may fix some type parameters if the return expression contains a function expression. So I am ensuring that anywhere that it's possible to fix type parameters, we go through that code path.
… fixingTypeParameters Conflicts: src/compiler/checker.ts
… fixingTypeParameters
… fixingTypeParameters
@yuit any more feedback? @DanielRosenwasser @ahejlsberg Do you have any feedback on this change? |
… fixingTypeParameters
… fixingTypeParameters
* | ||
* 1. undefined - this means we are not doing inferential typing, but we may do contextual typing, | ||
* which could cause us to assign a parameter type | ||
* 2. identityMapper - means we want to avoid assigning a parameter type, whether or not we are in |
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.
a parameter a type
👍 |
Fix type parameters upon subsequent visits to a parameter that caused fixing the first time
Fixes #2378.
The problem is that if a type parameter has already been given a type in the process of type argument inference, and caused type parameters to be fixed, we don't consistently fix the type parameters on a subsequent visit. See the bug for examples of how this can be observed.
The fix is that if a contextually typed parameter already has a type, we should still fix the type parameters that would have been fixed, had this been the first encounter of the given parameter.