From 47141797bed55eb10932c9a722a5132f50d4f3d8 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Mon, 16 Mar 2020 23:03:22 +0900 Subject: hash.c: Do not use the fast path (rb_yield_values) for lambda blocks As a semantics, Hash#each yields a 2-element array (pairs of keys and values). So, `{ a: 1 }.each(&->(k, v) { })` should raise an exception due to lambda's arity check. However, the optimization that avoids Array allocation by using rb_yield_values for blocks whose arity is more than 1 (introduced at b9d29603375d17c3d1d609d9662f50beaec61fa1 and some commits), seemed to overlook the lambda case, and wrongly allowed the code above to work. This change experimentally attempts to make it strict; now the code above raises an ArgumentError. This is an incompatible change; if the compatibility issue is bigger than our expectation, it may be reverted (until Ruby 3.0 release). [Bug #12706] --- NEWS.md | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'NEWS.md') diff --git a/NEWS.md b/NEWS.md index d760de7c11..3fabf7b331 100644 --- a/NEWS.md +++ b/NEWS.md @@ -121,6 +121,13 @@ Excluding feature bug fixes. your plan to https://github.com/ruby/xmlrpc or https://github.com/ruby/net-telnet. +* EXPERIMENTAL: Hash#each consistently yields a 2-element array [[Bug #12706]] + + * Now `{ a: 1 }.each(&->(k, v) { })` raises an ArgumentError + due to lambda's arity check. + * This is experimental; if it brings a big incompatibility issue, + it may be reverted until 2.8/3.0 release. + ## Stdlib compatibility issues Excluding feature bug fixes. -- cgit v1.2.3