Skip to content

Commit

Permalink
resolve conflict; ref #3281
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Nov 25, 2016
2 parents 7f05ba8 + b60d6c4 commit 79e3980
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
26 changes: 8 additions & 18 deletions mrbgems/mruby-struct/src/struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,15 @@ mrb_struct_s_def(mrb_state *mrb, mrb_value klass)
}
else {
if (argc > 0) name = argv[0];
if (argc > 1) rest = argv[1];
if (mrb_array_p(rest)) {
if (!mrb_nil_p(name) && mrb_symbol_p(name)) {
/* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */
mrb_ary_unshift(mrb, rest, name);
name = mrb_nil_value();
}
}
else {
pargv = &argv[1];
argcnt = argc-1;
if (!mrb_nil_p(name) && mrb_symbol_p(name)) {
/* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */
name = mrb_nil_value();
pargv = &argv[0];
argcnt++;
}
rest = mrb_ary_new_from_values(mrb, argcnt, pargv);
pargv = &argv[1];
argcnt = argc-1;
if (!mrb_nil_p(name) && mrb_symbol_p(name)) {
/* 1stArgument:symbol -> name=nil rest=argv[0]-[n] */
name = mrb_nil_value();
pargv = &argv[0];
argcnt++;
}
rest = mrb_ary_new_from_values(mrb, argcnt, pargv);
for (i=0; i<RARRAY_LEN(rest); i++) {
id = mrb_obj_to_sym(mrb, RARRAY_PTR(rest)[i]);
mrb_ary_set(mrb, rest, i, mrb_symbol_value(id));
Expand Down
6 changes: 6 additions & 0 deletions mrbgems/mruby-struct/test/struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,9 @@
Struct.remove_const :Test
end
end

assert("Struct.new does not allow array") do
assert_raise(TypeError) do
Struct.new("Test", [:a])
end
end

0 comments on commit 79e3980

Please sign in to comment.