Project

General

Profile

Bug #6039

lambda vs proc; #to_ary w/ splat bug

Added by ddebernardy (Denis de Bernardy) almost 8 years ago. Updated over 7 years ago.

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

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)

RUBY_VERSION
=> "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 master - Bug #5759: flatten calls to_ary on everythingRejected12/14/2011Actions
Related to Ruby master - Bug #5694: Proc#arity doesn't take optional arguments into account. Closed12/01/2011Actions

History

#3

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Assignee set to matz (Yukihiro Matsumoto)
#4

Updated by shyouhei (Shyouhei Urabe) over 7 years ago

  • Status changed from Open to Assigned

Updated by ko1 (Koichi Sasada) over 7 years ago

  • Status changed from Assigned to Rejected

This behavior is intended.

Also available in: Atom PDF