Bug #20094
closedInline while loop behavior changed unexpectedly in 3.3.0
Description
The behavior of the inline while loop has changed in 3.3.0. This unexpectedly broke my code and I couldn't find anything in the changelog about it so reporting it as a bug.
In ruby <= 3.2:
(p 1) while false # nothing
(p 1; p 2) while false # nothing
In ruby 3.3:
(p 1) while false # 1
(p 1; p 2) while false # 1 2
Essentially, if the left hand side looks like a statement, now it is treated as a do-while loop. In ruby 3.2 and less this only happened with explicit use of begin
and end
.
Updated by nobu (Nobuyoshi Nakada) 10 months ago
Updated by jeremyevans0 (Jeremy Evans) 10 months ago
- Status changed from Open to Closed
Updated by jeremyevans0 (Jeremy Evans) 10 months ago
- Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN to 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED
Updated by naruse (Yui NARUSE) 9 months ago
- Backport changed from 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED to 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE
ruby_3_3 119d447d42d4645ac919ee53f3ec294deaa7c59b merged revision(s) bc002971b6ad483dbf69b8a275c44412bb6ab954.
Updated by rbjl (Jan Lelis) 6 months ago ยท Edited
It seems like the bug is still present in Ruby 3.3.1:
(p 1) while false # 1
Updated by Eregon (Benoit Daloze) 6 months ago
Indeed:
$ ruby -ve '(p 1) while false'
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-linux]
$ ruby -ve '(p 1) while false'
ruby 3.3.1 (2024-04-23 revision c56cd86388) [x86_64-linux]
1
Updated by nevans (Nicholas Evans) 6 months ago
Can we reopen this bug (please), or should we create a new issue?
Updated by nagachika (Tomoyuki Chikanaga) 6 months ago
- ruby -v changed from 3.3.0 to 3.3.1
- Backport changed from 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE to 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED
I see the issue was fixed on master branch.
I will revert back Backport field to "3.3: REQUIRED", but stay the ticket status "Closed.
Updated by nagachika (Tomoyuki Chikanaga) 6 months ago
I have found that the backport commit was reverted at https://github.com/ruby/ruby/commit/9f18cbd7964f32f224e7d0efba79ee0476a442e0.
Updated by k0kubun (Takashi Kokubun) 5 months ago
- Backport changed from 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: REQUIRED to 3.0: UNKNOWN, 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONE
ruby_3_3 0044b6aefc656874adb9266829f19870dcd3d75e merged revision(s) bc002971b6ad483dbf69b8a275c44412bb6ab954.
Updated by k0kubun (Takashi Kokubun) 5 months ago
It was previously reverted presumably because the cherry-pick of bc002971b6ad483dbf69b8a275c44412bb6ab954 to ruby_3_3
doesn't really work. I had to manually create a whole backport patch without relying on git for that reason. I encourage people to file a backport pull request to ruby_3_3
(and make the CI green, which was the hard thing for this ticket) if you want to see a change backported to stable branches.
Updated by k0kubun (Takashi Kokubun) 5 months ago
It seems like the bug is still present in Ruby 3.3.1
Ruby 3.3.2 has been released today. It shouldn't have this issue.