Exclude variables' final types inside while true
if re-assigned before first break
#10538
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Consider the following:
typeof(x)
after the exit of thewhile
expression should not be affected by the assignment on(2)
, because(1)
must have been executed before any break could happen. This PR makes it so thattypeof(x)
becomesInt32
.Note that if
(1)
's RHS referencesx
itself then the exit type would still depend on(2)
as well as whatever typex
has before the whole loop:This issue was discovered while trying to determine whether
while exp; ...; end
is always semantically equivalent to the following, providedexp
isn't already thetrue
literal:while
loops would be a lot easier to reason about if all of them could be cast like this. This flow typing issue turned out to be a blocker whenever thewhile
condition contains an assignment (including #10350).