зеркало из https://github.com/github/ruby.git
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:
Родитель
3dab183c82
Коммит
771c8ed338
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>
|
||||
|
||||
* 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)
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
14
parse.y
14
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));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче