Skip to content

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

Merged
4 commits merged into
masterfrom
isContextSensitive
Aug 10, 2017
Merged

A function should be context-sensitive if its return expression is#17697
4 commits merged into
masterfrom
isContextSensitive

Conversation

@ghost
Copy link
Copy Markdown

@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
Comment thread src/compiler/checker.ts Outdated
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
Copy Markdown
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
Copy Markdown
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".

Comment thread src/compiler/checker.ts Outdated
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
Copy Markdown
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
Copy Markdown
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.

Comment thread src/compiler/checker.ts Outdated
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
Copy Markdown
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
Copy Markdown
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