-
Notifications
You must be signed in to change notification settings - Fork 13k
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
typestate sees break
as applying to the outermost loop
#2642
Comments
this may be a liveness bug? |
Maybe, but I'm pretty sure I know what the bug is if it's in typestate. @paulstansifer , can you post the error message? |
actually I think this is neither liveness nor typestate but rather typeck and something off in the (rather hokey) way that it tracks the notion of "bottom". |
this is the error that I see:
|
Yeah, not a typestate error. I can still take a look, though. |
To be honest, I am not sure that the type system ought to be in the business of tracking bottom. |
Oops, sorry folks. That's the same as the error I get. |
It's really useful if you want to return from inside an otherwise infinite loop, which is what led me to this bug. |
but why are you "assigning" the loop to a local variable in the first place? |
it seems to me that loops and complex constructs that may or may not be bottom should just have unit type. Something like |
I probably should've reduced it to an example that looks more like the code I'm interested in: fn f() -> uint {
loop {
if some_cond { ret 8u; }
loop { break; }
}
} In this case, we need bottom to acknowledge that nothing will ever fall off the end of the outer loop, preventing the need for a dummy, dead code |
I think I usually just use |
Yes, but the point of introducing |
Paul's example is more convincing. I guess we have to make it work due to the fact that loops are expressions and can appear in tail position in a block. sigh |
…Jung Followup for pr 2640 r? `@RalfJung`
…Jung Followup for pr 2640 r? `@RalfJung`
The following code compiles (as expected):
However, this code does not, as if the
break
were breaking out of the outer loop:The text was updated successfully, but these errors were encountered: