Skip to content

Commit

Permalink
Raise ArgumentError if trying to instance_exec proc created from method
Browse files Browse the repository at this point in the history
Fixes [Bug #18069]
  • Loading branch information
jeremyevans committed Aug 9, 2021
1 parent cc1d88d commit 3e2db2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 19 additions & 0 deletions test/ruby/test_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -816,6 +816,25 @@ def test_instance_exec
end
end

def test_instance_exec_method_to_proc
a = Class.new do
def a
1
end
end

b = Class.new do
def b(x)
a + x
end
end

bug18069 = '[ruby-dev:51089]'
assert_raise(ArgumentError, bug18069) do
a.new.instance_exec(1, &b.new.method(:b).to_proc)
end
end

def test_extend
assert_raise(ArgumentError) do
1.extend
Expand Down
4 changes: 1 addition & 3 deletions vm_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,9 +1977,7 @@ yield_under(VALUE under, VALUE self, int argc, const VALUE *argv, int kw_splat)
new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
break;
case block_handler_type_ifunc:
captured = VM_BH_TO_CAPT_BLOCK(block_handler);
new_captured = *captured;
new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
rb_raise(rb_eArgError, "cannot change self on proc created from method");
break;
case block_handler_type_proc:
is_lambda = rb_proc_lambda_p(block_handler) != Qfalse;
Expand Down

0 comments on commit 3e2db2f

Please sign in to comment.