Commit 32bfa1f1 authored by take_cheeze's avatar take_cheeze

Add invalid key type check in `Struct#[]=`.

parent 7bc4d08f
......@@ -672,7 +672,7 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val);
}
i = mrb_fixnum(idx);
i = mrb_int(mrb, idx);
if (i < 0) i = RSTRUCT_LEN(s) + i;
if (i < 0) {
mrb_raisef(mrb, E_INDEX_ERROR,
......
......@@ -41,6 +41,7 @@ assert('Struct#[]=', '15.2.18.4.3') do
cc[:m1] == 3
cc["m2"] = 3
assert_equal 3, cc["m2"]
assert_raise(TypeError) { cc[[]] = 3 }
end
assert('Struct#each', '15.2.18.4.4') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment