diff --git a/ChangeLog b/ChangeLog index c59369acd5..d0bcdfcf30 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Sun Sep 29 22:56:31 2013 Nobuyoshi Nakada + + * parse.y (rb_id_attrset): fix inconsistency with literals, allow + ID_ATTRSET and return it itself, but ID_JUNK cannot make ID_ATTRSET. + and raise a NameError instead of rb_bug() for invalid argument. + +Sun Sep 29 22:55:44 2013 Nobuyoshi Nakada + + * parse.y (rb_id_attrset): fix inconsistency with literals, allow + ID_ATTRSET and return it itself, but ID_JUNK cannot make ID_ATTRSET. + and raise a NameError instead of rb_bug() for invalid argument. + Sun Sep 29 18:45:05 2013 Kazuki Tsujimoto * vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args): diff --git a/ext/-test-/symbol/type.c b/ext/-test-/symbol/type.c index 37406d3853..e0b2fff2f9 100644 --- a/ext/-test-/symbol/type.c +++ b/ext/-test-/symbol/type.c @@ -27,8 +27,17 @@ bug_sym_##type##_p(VALUE self, VALUE name) \ FOREACH_ID_TYPES(define_symbol_type_p) +static VALUE +bug_sym_attrset(VALUE self, VALUE name) +{ + ID id = rb_to_id(name); + id = rb_id_attrset(id); + return ID2SYM(id); +} + void Init_type(VALUE klass) { - FOREACH_ID_TYPES(declare_symbol_type_p) + FOREACH_ID_TYPES(declare_symbol_type_p); + rb_define_singleton_method(klass, "attrset", bug_sym_attrset, 1); } diff --git a/parse.y b/parse.y index e20354909b..1f2eea9ca8 100644 --- a/parse.y +++ b/parse.y @@ -8885,17 +8885,23 @@ ID rb_id_attrset(ID id) { if (!is_notop_id(id)) { - rb_bug("rb_id_attrset: operator ID - %"PRIdVALUE, (VALUE)id); + switch (id) { + case tAREF: case tASET: + return tASET; /* only exception */ + } + rb_name_error(id, "cannot make operator ID :%s attrset", rb_id2name(id)); } else { int scope = (int)(id & ID_SCOPE_MASK); switch (scope) { case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL: - case ID_CONST: case ID_CLASS: case ID_JUNK: + case ID_CONST: case ID_CLASS: break; + case ID_ATTRSET: + return id; default: - rb_bug("rb_id_attrset: %s ID - %"PRIdVALUE, id_type_names[scope], - (VALUE)id); + rb_name_error(id, "cannot make %s ID %+"PRIsVALUE" attrset", + id_type_names[scope], ID2SYM(id)); } } diff --git a/test/-ext-/symbol/test_type.rb b/test/-ext-/symbol/test_type.rb index 427888eeb9..fe79502b83 100644 --- a/test/-ext-/symbol/test_type.rb +++ b/test/-ext-/symbol/test_type.rb @@ -91,6 +91,19 @@ module Test_Symbol assert_not_symtype("@@foo", :attrset?) assert_not_symtype("$foo", :attrset?) assert_not_symtype("[foo]", :attrset?) + assert_not_symtype("[foo]=", :attrset?) + assert_equal(:"foo=", Bug::Symbol.attrset("foo")) + assert_symtype(Bug::Symbol.attrset("foo"), :attrset?) + assert_equal(:"Foo=", Bug::Symbol.attrset("Foo")) + assert_symtype(Bug::Symbol.attrset("Foo"), :attrset?) + assert_equal(:"@foo=", Bug::Symbol.attrset("@foo")) + assert_symtype(Bug::Symbol.attrset("@foo"), :attrset?) + assert_equal(:"@@foo=", Bug::Symbol.attrset("@@foo")) + assert_symtype(Bug::Symbol.attrset("@@foo"), :attrset?) + assert_equal(:"$foo=", Bug::Symbol.attrset("$foo")) + assert_symtype(Bug::Symbol.attrset("$foo"), :attrset?) + assert_raise(NameError) {Bug::Symbol.attrset("[foo]")} + assert_equal(:[]=, Bug::Symbol.attrset(:[])) end end end