Bug #12671
closed
Updated by nobu (Nobuyoshi Nakada) almost 9 years ago
None-lambda doesn't mean that it never checks its arguments.
And if it's a lambda, it doesn't match the arity
value.
As for the implementation detail, there is no room for arity in ifunc
s.
Updated by headius (Charles Nutter) almost 9 years ago
JRuby implements Hash#to_proc as:
class Hash
def to_proc
method(:[]).to_proc
end
end
This allows us to present the proc as a lambda with correct arity:
$ jruby -e "pr = {}.to_proc; puts pr.arity; puts pr.lambda?"
1
true
It works for MRI too:
$ ruby23 -e "class Hash; def to_proc; method(:[]).to_proc; end; end; pr = {}.to_proc; puts pr.arity; puts pr.lambda?"
1
true
I think this is more representative of this proc's behavior. Can MRI do it this way?
Updated by mame (Yusuke Endoh) over 5 years ago
This ticket was briefly discussed at today's dev meeting, and matz said that the result of Hash#to_proc should be a lambda.
Updated by mame (Yusuke Endoh) over 5 years ago
- Status changed from Open to Closed
Applied in changeset git|d514ba8e17106c6d159c3902ac5456d6269731f8.
Proc
made by Hash#to_proc
should be a lambda [Bug ]
Like Symbol#to_proc
(f0b815dc670b61eba1daaa67a8613ac431d32b16)
Updated by marcandre (Marc-Andre Lafortune) almost 5 years ago
- Status changed from Closed to Open
Is there a reason why the arity was not fixed to 1
(instead of -1
)?
Updated by Eregon (Benoit Daloze) almost 5 years ago
Looking at the commit, should Hash#to_proc use rb_func_lambda_new()
instead of rb_func_proc_new()
? (and then rb_func_proc_new
is unused)
Also it seems confusing that rb_func_proc_new()
creates a lambda, so using rb_func_lambda_new()
seems better here.
Code changed quite a bit though around there.
Updated by Eregon (Benoit Daloze) almost 5 years ago
Proposed fix (simple as it gets): https://.com/ruby/ruby/pull/3370
Updated by Eregon (Benoit Daloze) almost 5 years ago
- Status changed from Open to Closed