Skip to content

Commit

Permalink
Fix crash when defining ivars on special constants
Browse files Browse the repository at this point in the history
[Bug #19339]
  • Loading branch information
peterzhu2118 committed Jan 17, 2023
1 parent f8249eb commit ed6fbb7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/ruby/test_variable.rb
Expand Up @@ -261,6 +261,12 @@ def test_special_constant_ivars
v.instance_variable_set(:@foo, :bar)
end

assert_raise_with_message(FrozenError, msg, "[Bug #19339]") do
v.instance_eval do
@a = 1
end
end

assert_nil EnvUtil.suppress_warning {v.instance_variable_get(:@foo)}
assert_not_send([v, :instance_variable_defined?, :@foo])

Expand Down
5 changes: 5 additions & 0 deletions vm_insnhelper.c
Expand Up @@ -1562,6 +1562,11 @@ vm_getinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, IVC ic)
static inline void
vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IVC ic)
{
if (RB_SPECIAL_CONST_P(obj)) {
rb_error_frozen_object(obj);
return;
}

shape_id_t dest_shape_id;
attr_index_t index;
vm_ic_atomic_shape_and_index(ic, &dest_shape_id, &index);
Expand Down

0 comments on commit ed6fbb7

Please sign in to comment.