Array#[]= should return assigning value; close #584

parent 97545127
......@@ -719,24 +719,21 @@ mrb_ary_aset(mrb_state *mrb, mrb_value self)
mrb_get_args(mrb, "*", &argv, &argc);
switch(argc) {
case 2:
if (mrb_fixnum_p(argv[0])) {
mrb_ary_set(mrb, self, mrb_fixnum(argv[0]), argv[1]);
}
else {
if (!mrb_fixnum_p(argv[0])) {
/* Should we support Range object for 1st arg ? */
mrb_raise(mrb, E_TYPE_ERROR, "expected Fixnum for 1st argument");
}
break;
mrb_ary_set(mrb, self, mrb_fixnum(argv[0]), argv[1]);
return argv[1];
case 3:
mrb_ary_splice(mrb, self, mrb_fixnum(argv[0]), mrb_fixnum(argv[1]), argv[2]);
break;
return argv[2];
default:
mrb_raise(mrb, E_ARGUMENT_ERROR, "wrong number of arguments");
return mrb_nil_value();
}
return self;
}
mrb_value
......
......@@ -74,8 +74,8 @@ assert('Array#[]=', '15.2.12.5.5') do
e3 = e1
end
[1,2,3].[]=(1,4) == [1, 4, 3] and
[1,2,3].[]=(1,2,3) == [1, 3] and
[1,2,3].[]=(1,4) == 4 and
[1,2,3].[]=(1,2,3) == 3 and
e2.class == ArgumentError and
e3.class == ArgumentError
end
......
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