Exclude variables' final types inside while true if re-assigned before first break#10538
Merged
straight-shoota merged 4 commits intocrystal-lang:masterfrom Mar 30, 2021
Merged
Conversation
asterite
reviewed
Mar 26, 2021
asterite
reviewed
Mar 26, 2021
straight-shoota
approved these changes
Mar 26, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thewhileexpression 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 referencesxitself then the exit type would still depend on(2)as well as whatever typexhas before the whole loop:This issue was discovered while trying to determine whether
while exp; ...; endis always semantically equivalent to the following, providedexpisn't already thetrueliteral:whileloops 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 thewhilecondition contains an assignment (including #10350).