[BUG] Non-working code snippet
Reported by oleg dashevskii | January 30th, 2008 @ 09:15 PM | in 1.0 preview
While testing #291 I created a small code snippet to assist myself. And it triggered some bug in Rubinius.
This DOESN'T WORK:
def hexputs(x)
puts (0...x.length).map { |i| sprintf("%02x", x[i]) }.join(' ')
end
hexputs("abc")
~/work/rubinius% shotgun/rubinius y1.rb
0...3
An exception has occurred:
No method 'map' on an instance of NilClass. (NoMethodError)
Backtrace:
Kernel(NilClass)#map (method_missing_cv) at kernel/core/kernel.rb:540
Object#hexputs at y1.rb:2
main.__script__ at y1.rb:5
CompiledMethod#as_script at kernel/core/compiled_method.rb:206
Compile.single_load at kernel/core/compile.rb:219
Compile.load_from_extension at kernel/core/compile.rb:291
main.__script__ at kernel/loader.rb:176
But if I change code a bit (introduce variable 's'), it WORKS:
def hexputs(x)
s = (0...x.length).map { |i| sprintf("%02x", x[i]) }.join(' ')
puts s
end
hexputs("abc")
What's more interesting, after getting rid of function it also works:
x = "abc"
puts (0...x.length).map { |i| sprintf("%02x", x[i]) }.join(' ')
Another way to get first snippet working is to enclose puts argument in parentheses:
def hexputs(x)
puts ((0...x.length).map { |i| sprintf("%02x", x[i]) }.join(' '))
end
hexputs("abc")
Needless to say, MRI is OK with all the cases.
I wish I could write a spec for that.
Comments and changes to this ticket
-

-
Wilson Bilkovich March 15th, 2008 @ 12:30 AM
- → State changed from new to open
- → Assigned user changed from to Wilson Bilkovich
Here is a slightly more minimal reproduction.
## FAILS def chaos(x = nil) puts (0...5).first end chaos ## WORKS def chaos puts (0...5).first end chaos -
Wilson Bilkovich February 28th, 2008 @ 05:01 PM
- → Title changed from [BUG] Non-working code snippet to [BUG] Incorrect bytecode generated for the first line of a method
-
Wilson Bilkovich February 28th, 2008 @ 07:18 PM
- → Title changed from [BUG] Incorrect bytecode generated for the first line of a method to [BUG] Incorrect sexp for the first line of a method
-
Wilson Bilkovich March 15th, 2008 @ 12:31 AM
- → Assigned user changed from Wilson Bilkovich to Evan Phoenix
-
Ryan Davis May 6th, 2008 @ 09:46 AM
- → Title changed from [BUG] Incorrect sexp for the first line of a method to [BUG] Non-working code snippet
- → State changed from open to new
- → Assigned user changed from Evan Phoenix to Ryan Davis
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 »
