Project

General

Profile

Actions

Bug #16948

closed

hash.each(&method(:something)) behavior changed without warning on master

Added by byroot (Jean Boussier) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.8.0dev (2020-06-08T04:15:05Z master 465b5dc124) [x86_64-darwin19]
[ruby-core:98711]

Description

I'm testing our app against ruby master as part of https://bugs.ruby-lang.org/issues/16895, and found the following unexpected change:

$VERBOSE = true

def foo(a, b)
  p [a, b]
end

{1 => 2}.each(&method(:foo))
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin19]
$ ruby /tmp/debug.rb
[1, 2]
$ ruby -v
ruby 2.8.0dev (2020-06-08T04:15:05Z master 465b5dc124) [x86_64-darwin19]
$ ruby /tmp/debug.rb
/tmp/debug.rb:3:in `foo': wrong number of arguments (given 1, expected 2) (ArgumentError)
	from /tmp/debug.rb:7:in `each'
	from /tmp/debug.rb:7:in `<main>'

I'm not sure if this was intended, but I would expect that either 2.7 would warn about this, or that it would continue to work on 2.8/3.0


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #12706: Hash#each yields inconsistent number of argsClosedActions

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

This was a deliberate change in 47141797bed55eb10932c9a722a5132f50d4f3d8. As the commit message states, it may be reverted depending on the extent of the compatibility issues.

Updated by byroot (Jean Boussier) almost 4 years ago

it may be reverted depending on the extent of the compatibility issues.

My bad I should have seen it in NEWS.md.

it may be reverted depending on the extent of the compatibility issues.

For what it's worth I found only two problematic call sites in a rather large application, and the fix was trivial.

I suppose this ticket can be closed.

Actions #3

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

  • Related to Bug #12706: Hash#each yields inconsistent number of args added
Actions #4

Updated by jeremyevans0 (Jeremy Evans) almost 4 years ago

  • Status changed from Open to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0