mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parse.y: fix inconsistency with literals
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3dab183c82
commit
771c8ed338
4 changed files with 45 additions and 5 deletions
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
||||||
|
Sun Sep 29 22:56:31 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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 <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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 <kazuki@callcc.net>
|
Sun Sep 29 18:45:05 2013 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||||
|
|
||||||
* vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args):
|
* vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args):
|
||||||
|
|
|
@ -27,8 +27,17 @@ bug_sym_##type##_p(VALUE self, VALUE name) \
|
||||||
|
|
||||||
FOREACH_ID_TYPES(define_symbol_type_p)
|
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
|
void
|
||||||
Init_type(VALUE klass)
|
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);
|
||||||
}
|
}
|
||||||
|
|
14
parse.y
14
parse.y
|
@ -8885,17 +8885,23 @@ ID
|
||||||
rb_id_attrset(ID id)
|
rb_id_attrset(ID id)
|
||||||
{
|
{
|
||||||
if (!is_notop_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 {
|
else {
|
||||||
int scope = (int)(id & ID_SCOPE_MASK);
|
int scope = (int)(id & ID_SCOPE_MASK);
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
|
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;
|
break;
|
||||||
|
case ID_ATTRSET:
|
||||||
|
return id;
|
||||||
default:
|
default:
|
||||||
rb_bug("rb_id_attrset: %s ID - %"PRIdVALUE, id_type_names[scope],
|
rb_name_error(id, "cannot make %s ID %+"PRIsVALUE" attrset",
|
||||||
(VALUE)id);
|
id_type_names[scope], ID2SYM(id));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue