Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Feb 7, 2018

Fixes #21542

The problem was that in checkYieldExpression, we call checkExpressionCached to get the type of the yielded expression. checkExpressionCached resets flowLoopStart, so we don't detect that we're inside a loop in the flow graph.

The fix is that we don't actually need to check the yield expression to get its type -- the type of a yield expression is always anyType, so we can just return that early from getTypeOfExpression.

@ghost ghost requested a review from sandersn February 7, 2018 17:14
@sandersn
Copy link
Member

sandersn commented Feb 7, 2018

You can also fix this by switching back to checkExpression, right? I don't know whether it's good to put more code in getTypeOfExpression, since it's supposed to be a fast path. Opinions @ahejlsberg ?

@sandersn sandersn requested a review from ahejlsberg February 7, 2018 22:04
@sandersn
Copy link
Member

sandersn commented Feb 7, 2018

Especially if we believe yield to be used rarely, then making yield checking slower is probably the right tradeoff.

@typescript-bot
Copy link
Collaborator

Thanks for your contribution. This PR has not been updated in a while and cannot be automatically merged at the time being. For housekeeping purposes we are closing stale PRs. If you'd still like to continue working on this PR, please leave a message and one of the maintainers can reopen it.

@ghost ghost reopened this Nov 15, 2018
@ghost ghost assigned sandersn Nov 16, 2018
@sandersn
Copy link
Member

Turns out the infinite loop has been fixed already. I reverted the code change but kept the test.

@sandersn sandersn merged commit 79b9fa5 into master Nov 19, 2018
@sandersn sandersn deleted the yieldExpressionInFlowLoop branch November 19, 2018 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generator function + noImplicitAny triggers "Maximum call stack size exceeded"
2 participants