diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2020-03-16 23:32:55 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2020-03-16 23:38:26 +0900 |
commit | d514ba8e17106c6d159c3902ac5456d6269731f8 (patch) | |
tree | 4a0be3434f9aeeea98f7f94f6d830a0d19a52377 | |
parent | 304538e6ff64b8daadde5456988fb9f82c6a4849 (diff) |
`Proc` made by `Hash#to_proc` should be a lambda [Bug #12671]
Like `Symbol#to_proc` (f0b815dc670b61eba1daaa67a8613ac431d32b16)
-rw-r--r-- | proc.c | 8 | ||||
-rw-r--r-- | spec/ruby/core/hash/to_proc_spec.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 2 |
3 files changed, 16 insertions, 6 deletions
@@ -667,7 +667,7 @@ bind_location(VALUE bindval) } static VALUE -cfunc_proc_new(VALUE klass, VALUE ifunc, int8_t is_lambda) +cfunc_proc_new(VALUE klass, VALUE ifunc) { rb_proc_t *proc; cfunc_proc_t *sproc; @@ -685,7 +685,7 @@ cfunc_proc_new(VALUE klass, VALUE ifunc, int8_t is_lambda) /* self? */ RB_OBJ_WRITE(procval, &proc->block.as.captured.code.ifunc, ifunc); - proc->is_lambda = is_lambda; + proc->is_lambda = TRUE; return procval; } @@ -736,14 +736,14 @@ MJIT_FUNC_EXPORTED VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val) { struct vm_ifunc *ifunc = rb_vm_ifunc_proc_new(func, (void *)val); - return cfunc_proc_new(rb_cProc, (VALUE)ifunc, 0); + return cfunc_proc_new(rb_cProc, (VALUE)ifunc); } MJIT_FUNC_EXPORTED VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc) { struct vm_ifunc *ifunc = rb_vm_ifunc_new(func, (void *)val, min_argc, max_argc); - return cfunc_proc_new(rb_cProc, (VALUE)ifunc, 1); + return cfunc_proc_new(rb_cProc, (VALUE)ifunc); } static const char proc_without_block[] = "tried to create Proc object without a block"; diff --git a/spec/ruby/core/hash/to_proc_spec.rb b/spec/ruby/core/hash/to_proc_spec.rb index 3e7e57d11f..700621f162 100644 --- a/spec/ruby/core/hash/to_proc_spec.rb +++ b/spec/ruby/core/hash/to_proc_spec.rb @@ -19,8 +19,16 @@ describe "Hash#to_proc" do @proc = @hash.to_proc end - it "is not a lambda" do - @proc.lambda?.should == false + ruby_version_is ""..."2.8" do + it "is not a lambda" do + @proc.lambda?.should == false + end + end + + ruby_version_is "2.8" do + it "is a lambda" do + @proc.lambda?.should == true + end end it "raises ArgumentError if not passed exactly one argument" do diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index cc13e3f6a5..c0ec078403 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1627,6 +1627,8 @@ class TestHash < Test::Unit::TestCase } assert_equal([10, 20, 30], [1, 2, 3].map(&h)) + + assert_equal(true, h.to_proc.lambda?) end def test_transform_keys |