-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Odd behavior with 'until' vs '&&' #4239
Comments
On gitter, @zatherz noticed that the same issue comes up if you use |
Reduced: a = nil
until a
a = 1
end
p typeof(a) # => (Int32 | Nil) Basically |
Well, that's the first issue. But the second one seems more significant to me! |
Reduced second issue with no infinite loop: To sum it up, it seems like setting the value of EDIT: EDIT 2: |
@drosehn Sorry, I didn't see the second issue the first time I read it. I stopped at the first issue. It's probably better to report issues separately, and try to reduce them as much as possible so the bug is super clear. I split this issue in two which mention the bugs in a reduced way: #4242 and #4243 |
This is on:
I don't understand what is happening in the following. It seems like either
until
or&&
is not processed correctly ( and just try to search for issues with&&
! ):There are two problems I hit with this, and perhaps they are related. First off, if I do not include:
then crystal fails with a compile-time error on
if low_value > high_value
, complaining thatno overload matches 'Int32#>' with type (Int32 | Nil)
. However, I should not exit theuntil
loop unless bothlow_value
andhigh_value
are not-nil, so why do I need those two checks?The other issue is that I happened to use
until low_value && high_value
instead of usingwhile low_value.nil? || high_value.nil?
. If I run the above code using thewhile
statement, it works as expected:But if I run it with the
until
statement, the result is:Why is
low_value
being reset tonil
each time through theuntil
loop? Given the logic inside the loop, I can change thatuntil
to beuntil high_value
, and then it behaves as expected. Note that if I did use that condition, then I would understand why I need the check forlow_value.nil?
outside of the loop.The text was updated successfully, but these errors were encountered: