next causes Integer#times to lose count
Reported by Adam Shelly | February 27th, 2008 @ 12:22 AM | in 1.0 preview
a 'next' in the middle of an integer#times loop causes the loop execute at least one extra time.
ads@andLinux:~/rubinius/code/work$ more nextbug.rb
a = []
2.times do
a << 1
if a.size==1
next
end
a << 2
end
p a
p a == [1,1,2]
ads@andLinux:~/rubinius/code/work$ ruby nextbug.rb
[1, 1, 2]
true
ads@andLinux:~/rubinius/code/work$ rbx nextbug.rb
[1, 1, 2, 1, 2]
false
Comments and changes to this ticket
-
Wilson Bilkovich February 28th, 2008 @ 10:38 AM
- → State changed from new to open
- → Assigned user changed from to Wilson Bilkovich
Adding a block argument (2.times do |z|, for example) causes this code to behave properly.
That means it is due to the compiler plugin that inlines Fixnum#times code.
Specifically, class CompilerInlining in lib/compiler/plugins.rb
-
Brian Ford March 11th, 2008 @ 01:44 PM
- → State changed from open to resolved
The part of the plugin that was failing for this ticket has been fixed. However, the plugin is currently disabled for now awaiting fixes to handling break. A bunch of specs have been added to catch regressions once the plugin is re-enabled.
Resolving for now. Reopen if necessary.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
