Skip to content

Wrong inferred type in while and if with block conditions #11561

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

Closed
lnicola opened this issue Feb 26, 2022 · 5 comments · Fixed by #11567
Closed

Wrong inferred type in while and if with block conditions #11561

lnicola opened this issue Feb 26, 2022 · 5 comments · Fixed by #11567

Comments

@lnicola
Copy link
Member

lnicola commented Feb 26, 2022

fn main() {
    while { true } {}
       // ^ Expected (), got bool
}
@lnicola
Copy link
Member Author

lnicola commented Feb 26, 2022

@lnicola
Copy link
Member Author

lnicola commented Feb 26, 2022

CC @ChayimFriedman2

@Veykril
Copy link
Member

Veykril commented Feb 26, 2022

Ah, that is because condition is now an Expr node, so when it is a BlockExpr we actually have two BlockExpr children for these which causes the HasLoopBody::loop_body call to return the condition instead of the body tripping up lowering and typecheck.

Similar thing I assume will happen for if expressions as well now.

It's the same problem I have fixed for for loops some time ago here #10668

@lnicola lnicola changed the title Wrong inferred type in while with block condition Wrong inferred type in while and if with block conditions Feb 26, 2022
bors bot added a commit that referenced this issue Feb 26, 2022
11565: fix: Fix body selection in while loops r=Veykril a=lnicola

CC #11561

Co-authored-by: Laurențiu Nicola <[email protected]>
@ChayimFriedman2
Copy link
Contributor

ChayimFriedman2 commented Feb 26, 2022

It's interesting as it's very hard to prevent this kind of issues ahead of time. Fixed syntax trees can do that, but in our current model things can break unexpectedly.

CC #6584.

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 a pull request may close this issue.

3 participants