Project

General

Profile

Bug #13391

wrong number of arguments error for Hash#map when lambda given

Added by tomog105 (Tomohiro Ogoke) over 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
[ruby-dev:50063]

Description

内容

Ruby 2.4.1 にて Hash オブジェクトの #map に 2つの引数を受け取る lambda を渡した際、
arguments error が発生します。

Ruby 2.4.0, ないし 2.3.4 では同じコードを実行した際にはエラーは発生していませんでしたが、
trunk でも同じエラーが発生します。

再現コード

% cat lambda.rb
hash = { a: 'hoge', b: 'fuga' }
lambda = -> (k, v) { p "#{k}:#{v}" }
hash.map(&lambda)

実行結果

% ruby -v lambda.rb
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
lambda.rb:2:in `block in <main>': wrong number of arguments (given 1, expected 2) (ArgumentError)
    from lambda.rb:3:in `each'
    from lambda.rb:3:in `map'
    from lambda.rb:3:in `<main>'

% RBENV_VERSION=2.5.0-dev ruby -v lambda.rb
ruby 2.5.0dev (2017-03-31 trunk 58224) [x86_64-darwin15]
    from lambda.rb:3:in `<main>'
    from lambda.rb:3:in `map'
    from lambda.rb:3:in `each'
lambda.rb:2:in `block in <main>': wrong number of arguments (given 1, expected 2) (ArgumentError)

% RBENV_VERSION=2.4.0 ruby -v lambda.rb
ruby 2.4.0p0 (2016-12-24 revision 57164) [x86_64-darwin15]
"a:hoge"
"b:fuga"

% RBENV_VERSION=2.3.4 ruby -v lambda.rb
ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-darwin15]
"a:hoge"
"b:fuga"

また、 #map ではなく #each を使う場合には、同じ lambda ブロックを渡した際でもエラーにはなりません。

% cat lambda_each.rb
hash = { a: 'hoge', b: 'fuga' }
lambda = -> (k, v) { p "#{k}:#{v}" }
hash.each(&lambda)

% ruby -v lambda_each.rb
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
"a:hoge"
"b:fuga"

% RBENV_VERSION=2.5.0-dev ruby -v lambda_each.rb
ruby 2.5.0dev (2017-03-31 trunk 58224) [x86_64-darwin15]
"a:hoge"
"b:fuga"

Related issues

Related to Ruby master - Bug #12705: yielding args to a lambda uses block/proc rather than lambda/method semanticsClosednobu (Nobuyoshi Nakada)Actions
Has duplicate Ruby master - Bug #13404: Hash#any? yields arguments to lambdas with proc semanticsRejectedActions
#1

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Related to Bug #12705: yielding args to a lambda uses block/proc rather than lambda/method semantics added
#3

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Has duplicate Bug #13404: Hash#any? yields arguments to lambdas with proc semantics added

Updated by hsbt (Hiroshi SHIBATA) over 3 years ago

  • Assignee set to ko1 (Koichi Sasada)
  • Status changed from Open to Assigned
#5

Updated by nobu (Nobuyoshi Nakada) over 3 years ago

  • Status changed from Assigned to Closed

Applied in changeset trunk|r59358.


vm_eval.c: rb_lambda_call

  • enum.c (enum_collect): make the block arity same as the given
    block. [Bug #13391]

  • internal.h (vm_ifunc): store arity instead of unused id.

  • proc.c (rb_vm_block_min_max_arity): return ifunc arity.

  • vm_eval.c (rb_lambda_call): call method with lambda block.

#6

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: REQUIRED
#7

Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) about 3 years ago

  • Backport changed from 2.2: DONTNEED, 2.3: DONTNEED, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONTNEED, 2.4: DONE

ruby_2_4 r59500 merged revision(s) 59357,59358.

Also available in: Atom PDF