mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
remove unnecessary intern; access to non-member cause IndexError
This commit is contained in:
@@ -125,7 +125,7 @@ mrb_struct_getmember(mrb_state *mrb, mrb_value obj, mrb_sym id)
|
||||
return ptr[i];
|
||||
}
|
||||
}
|
||||
mrb_name_error(mrb, id, "%S is not struct member", mrb_sym2str(mrb, id));
|
||||
mrb_raisef(mrb, E_INDEX_ERROR, "%S is not struct member", mrb_sym2str(mrb, id));
|
||||
return mrb_nil_value(); /* not reached */
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ mrb_struct_set(mrb_state *mrb, mrb_value obj, mrb_value val)
|
||||
return ptr[i] = val;
|
||||
}
|
||||
}
|
||||
mrb_name_error(mrb, mid, "`%S' is not a struct member",
|
||||
mrb_raisef(mrb, E_INDEX_ERROR, "`%S' is not a struct member",
|
||||
mrb_sym2str(mrb, mid));
|
||||
return mrb_nil_value(); /* not reached */
|
||||
}
|
||||
@@ -544,7 +544,7 @@ mrb_struct_aref_id(mrb_state *mrb, mrb_value s, mrb_sym id)
|
||||
return ptr[i];
|
||||
}
|
||||
}
|
||||
mrb_name_error(mrb, id, "no member '%S' in struct", mrb_sym2str(mrb, id));
|
||||
mrb_raisef(mrb, E_INDEX_ERROR, "no member '%S' in struct", mrb_sym2str(mrb, id));
|
||||
return mrb_nil_value(); /* not reached */
|
||||
}
|
||||
|
||||
@@ -572,8 +572,16 @@ mrb_struct_aref_n(mrb_state *mrb, mrb_value s, mrb_value idx)
|
||||
{
|
||||
mrb_int i;
|
||||
|
||||
if (mrb_string_p(idx) || mrb_symbol_p(idx)) {
|
||||
return mrb_struct_aref_id(mrb, s, mrb_obj_to_sym(mrb, idx));
|
||||
if (mrb_string_p(idx)) {
|
||||
mrb_value sym = mrb_check_intern_str(mrb, idx);
|
||||
|
||||
if (mrb_nil_p(sym)) {
|
||||
mrb_raisef(mrb, E_INDEX_ERROR, "no member '%S' in struct", idx);
|
||||
}
|
||||
idx = sym;
|
||||
}
|
||||
if (mrb_symbol_p(idx)) {
|
||||
return mrb_struct_aref_id(mrb, s, mrb_symbol(idx));
|
||||
}
|
||||
|
||||
i = mrb_fixnum(idx);
|
||||
@@ -619,7 +627,7 @@ mrb_struct_aset_id(mrb_state *mrb, mrb_value s, mrb_sym id, mrb_value val)
|
||||
return val;
|
||||
}
|
||||
}
|
||||
mrb_name_error(mrb, id, "no member '%S' in struct", mrb_sym2str(mrb, id));
|
||||
mrb_raisef(mrb, E_INDEX_ERROR, "no member '%S' in struct", mrb_sym2str(mrb, id));
|
||||
return val; /* not reach */
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user