-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Deeper type inference in context sensitive arguments #1861
Conversation
// First infer from arguments that are not context sensitive | ||
var inferenceMapper = createInferenceMapper(context); | ||
|
||
// First infer from all arguments using wildcards for all context sensitive function expressions |
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.
Make this comment First infer from all arguments, but use wildcards for all context sensitive expressions.
The "but" actually would really help to point out that this is a special case.
It is strange that we only have 2 affected baselines, and only in one of them did we see that leaked type parameter issue. This change really needs more test coverage. |
Please add tests for both of these changes. |
I'm fine with this code change, but it needs tests. |
👍 |
Deeper type inference in context sensitive arguments
Fixes #1181.
Previously, context sensitive arguments (arguments containing function expressions that are subject to contextual typing) would be completely ignored in the first round of type inference. With this change we instead infer from all arguments in the first round, but treat context sensitive function expressions as wildcards from which no inferences are made.
This example would previously infer
{}
for T because the object literal argument was excluded from the first round of type inference. We now include the argument in the first round, but treat the context sensitive arrow functionvalue => s = value
as a wildcard. That allows us to inferstring
forT
from the (non-sensitive) arrow function() => s
. In the second round of inference we then end up fixingT
and assigning the inferred typestring
to thevalue
parameter.This also fixes a bug related to #1648 where the
contextualMapper
argument wasn't being propagated into a parenthesized expression, causing us to leak a type parameter.