diff --git a/ChangeLog b/ChangeLog index 4c0759e7f6..fbad1546e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Mar 16 20:03:35 2016 Nobuyoshi Nakada + + * proc.c (proc_binding): proc from symbol can not make a binding. + [ruby-core:74100] [Bug #12137] + Wed Mar 16 18:42:45 2016 Martin Duerst * test/ruby/enc/test_case_mapping.rb: Fixed and activated a test for Cherokee. diff --git a/proc.c b/proc.c index 6155dc0d35..8b1141a5d3 100644 --- a/proc.c +++ b/proc.c @@ -2658,6 +2658,7 @@ proc_binding(VALUE self) GetProcPtr(self, proc); envval = rb_vm_proc_envval(proc); iseq = proc->block.iseq; + if (SYMBOL_P(iseq)) goto error; if (RUBY_VM_IFUNC_P(iseq)) { struct vm_ifunc *ifunc = (struct vm_ifunc *)iseq; if (IS_METHOD_PROC_IFUNC(ifunc)) { @@ -2666,6 +2667,7 @@ proc_binding(VALUE self) iseq = rb_method_iseq(method); } else { + error: rb_raise(rb_eArgError, "Can't create Binding from C level Proc"); } } diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 9c51e26200..8bb9902317 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -176,6 +176,15 @@ class TestSymbol < Test::Unit::TestCase end; end + def test_to_proc_binding + assert_separately([], <<~"end;", timeout: 1) # do + bug12137 = '[ruby-core:74100] [Bug #12137]' + assert_raise(ArgumentError, bug12137) { + :succ.to_proc.binding + } + end; + end + def test_call o = Object.new def o.foo(x, y); x + y; end