Skip to content

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

Merged
merged 12 commits into from
Jul 17, 2015

Conversation

JsonFreeman
Copy link
Contributor

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.

assignContextualParameterTypes(signature, contextualSignature, contextualMapper || identityMapper);
}
if (!node.type && !signature.resolvedReturnType) {
if (mightFixTypeParameters || !node.type && !signature.resolvedReturnType) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@JsonFreeman
Copy link
Contributor Author

@yuit any more feedback?

@DanielRosenwasser @ahejlsberg Do you have any feedback on this change?

*
* 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
Copy link
Member

Choose a reason for hiding this comment

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

a parameter a type

@DanielRosenwasser
Copy link
Member

👍

JsonFreeman added a commit that referenced this pull request Jul 17, 2015
Fix type parameters upon subsequent visits to a parameter that caused fixing the first time
@JsonFreeman JsonFreeman merged commit 2c5ba08 into master Jul 17, 2015
@JsonFreeman JsonFreeman deleted the fixingTypeParameters branch July 17, 2015 23:05
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type parameters do not get fixed when the compiler visits the same signature multiple times
6 participants