Bug #6039

lambda vs proc; #to_ary w/ splat bug

Added by Denis de Bernardy about 2 years ago. Updated almost 2 years ago.

[ruby-core:42689]
Status:Rejected
Priority:Normal
Assignee:Yukihiro Matsumoto
Category:-
Target version:-
ruby -v:1.9.3 Backport:

Description

to_ary apparently gets called in edge cases when a proc has a splat argument:

good = Class.new do
def to_ary
[:bad]
end
end.new

foo = lambda { |*bar| bar.first }
foo.call(good)

foo = lambda { |bar, *baz| bar }
foo.call(good)

foo = proc { |*bar| bar.first }
foo.call(good)

foo = proc { |bar, *baz| bar }
foo.call(good)

RUBYVERSION
=> "1.9.3"
good = Class.new do
?> def to
ary
[:bad]
end
end.new
=> #<#Class:0x00000100a39c50:0x00000100a399d0>

?> foo = lambda { |*bar| bar.first }
=> #
foo.call(good)
=> #<#Class:0x00000100a39c50:0x00000100a399d0>

?> foo = lambda { |bar, *baz| bar }
=> #
foo.call(good)
=> #<#Class:0x00000100a39c50:0x00000100a399d0>

?> foo = proc { |*bar| bar.first }
=> #Proc:0x000001009aed80@(irb):330
foo.call(good)
=> #<#Class:0x00000100a39c50:0x00000100a399d0>

?> foo = proc { |bar, *baz| bar }
=> #Proc:0x000001010102a0@(irb):333
foo.call(good)
=> :bad


Related issues

Related to ruby-trunk - Bug #5759: flatten calls to_ary on everything Rejected 12/14/2011
Related to ruby-trunk - Bug #5694: Proc#arity doesn't take optional arguments into account. Closed 12/01/2011

History

#3 Updated by Koichi Sasada about 2 years ago

  • Assignee set to Yukihiro Matsumoto

#4 Updated by Shyouhei Urabe about 2 years ago

  • Status changed from Open to Assigned

#5 Updated by Koichi Sasada almost 2 years ago

  • Status changed from Assigned to Rejected

This behavior is intended.

Also available in: Atom PDF