You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copying over from the other issue:
Using while !(a && b): https://carc.in/#/r/1t8j (unexpected behavior)
Using while !a || !b: https://carc.in/#/r/1t8n (expected behavior)
Using while !(Glob.a && b) (Glob is a class): https://carc.in/#/r/1t8p (expected behavior)
Using while !Glob.a || !b (same result): https://carc.in/#/r/1t8q (expected behavior)
Using while !(a && b), assigning a to Glob.a: https://carc.in/#/r/1t8r (unexpected behavior with a, expected behavior with Glob.a)
Using while !(a && b), assigning a to Glob.a: https://carc.in/#/r/1t8s (expected behavior with both a and Glob.a)
To sum it up, it seems like setting the value of a in the scope of a while !(a && b) actually creates a new local variable instead of modifying the one in the outer scope, while while !a || !b has the expected result of modifying the local variable in the outer scope.
EDIT:
First test, but printing the value of a after the loop: https://carc.in/#/r/1t8u
Actually, it does change the variable of the outer scope, but the value of a at the beginning of the scope of each loop is set back to the initial value before the loop?
EDIT 2:
Expanding the while condition of the first test from !(a && b) to !((a != nil) && b) produces expected behavior: https://carc.in/#/r/1t90
But, expanding the condition from !(a && b) to !(!a.nil? && b) retains the unexpected effect: https://carc.in/#/r/1t92
Given:
The above code will print
x # => nil
forever, which is wrong becausex
is clearly assigned the value1
inside the loop.The same happens with
until
:(but
until exp
is currently re-written towhile !exp
so the above is logical to happen)Extracted from #4239
The text was updated successfully, but these errors were encountered: