Skip to content

A function should be context-sensitive if its return expression is #17697

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
4 commits merged into from
Aug 10, 2017

Conversation

ghost
Copy link

@ghost ghost commented Aug 9, 2017

Fixes #17586
If we're going to do this, we should also consider caching this function, since it gets called a lot.

@ghost ghost requested a review from sandersn August 9, 2017 17:46
if (node.kind !== SyntaxKind.ArrowFunction) {
// If the first parameter is not an explicit 'this' parameter, then the function has
// an implicit 'this' parameter which is subject to contextual typing. Otherwise we
// know that all parameters (including 'this') have type annotations and nothing is
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this comment still accurate?

Copy link
Member

Choose a reason for hiding this comment

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

"nothing is subject to contextual typing" should change to read "only the return type could still be subject to contextual typing".

const parameter = firstOrUndefined(node.parameters);
return !(parameter && parameterIsThisKeyword(parameter));

// TODO(anhans): A block should be context-sensitive if it has a context-sentitive return value.
Copy link
Member

Choose a reason for hiding this comment

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

typo:sensitive

Copy link
Author

Choose a reason for hiding this comment

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

(This is a response to comment above this -- github won't let me respond to that for some reason.) I'll just remove the second half of this comment since it doesn't add much that isn't already clear from reading the function's code.

if (node.kind !== SyntaxKind.ArrowFunction) {
// If the first parameter is not an explicit 'this' parameter, then the function has
// an implicit 'this' parameter which is subject to contextual typing. Otherwise we
// know that all parameters (including 'this') have type annotations and nothing is
Copy link
Member

Choose a reason for hiding this comment

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

"nothing is subject to contextual typing" should change to read "only the return type could still be subject to contextual typing".

@rbuckton
Copy link
Contributor

rbuckton commented Aug 9, 2017

Can you address the merge conflicts?

@ghost ghost merged commit fe3a05e into master Aug 10, 2017
@ghost ghost deleted the isContextSensitive branch August 10, 2017 14:08
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
This pull request was closed.
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.

3 participants