1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

parse.y: non-local/const attrset

* parse.y (rb_id_attrset): allow other than ID_ATTRSET.
* parse.y (intern_str): ditto.  try stem ID for ID_INSTANCE,
  ID_GLOBAL, ID_CLASS, ID_JUNK too.  [Bug #8756]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-08-10 04:53:31 +00:00
parent 90749b1f2a
commit 0dd8ec36c0
3 changed files with 42 additions and 21 deletions

View file

@ -1,3 +1,10 @@
Sat Aug 10 13:53:22 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (rb_id_attrset): allow other than ID_ATTRSET.
* parse.y (intern_str): ditto. try stem ID for ID_INSTANCE,
ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756]
Sat Aug 10 12:49:50 2013 Kouhei Sutou <kou@cozmixng.org>
* lib/rexml/parsers/baseparser.rb

52
parse.y
View file

@ -8785,7 +8785,11 @@ rb_id_attrset(ID id)
}
else {
int scope = (int)(id & ID_SCOPE_MASK);
if (scope != ID_LOCAL && scope != ID_CONST) {
switch (scope) {
case ID_LOCAL: case ID_INSTANCE: case ID_GLOBAL:
case ID_CONST: case ID_CLASS: case ID_JUNK:
break;
default:
rb_bug("rb_id_attrset: %s ID - %"PRIdVALUE, id_type_names[scope],
(VALUE)id);
@ -10415,24 +10419,25 @@ intern_str(VALUE str)
}
}
}
if (m[last] == '=') {
/* attribute assignment */
id = rb_intern3(name, last, enc);
if (id > tLAST_OP_ID && !is_attrset_id(id)) {
enc = rb_enc_get(rb_id2str(id));
id = rb_id_attrset(id);
goto id_register;
}
id = ID_ATTRSET;
break;
}
if (name[last] == '=') {
/* attribute assignment */
id = rb_intern3(name, last, enc);
if (id > tLAST_OP_ID && !is_attrset_id(id)) {
enc = rb_enc_get(rb_id2str(id));
id = rb_id_attrset(id);
goto id_register;
}
else if (rb_enc_isupper(m[0], enc)) {
id = ID_ATTRSET;
}
else if (id == 0) {
if (rb_enc_isupper(m[0], enc)) {
id = ID_CONST;
}
}
else {
id = ID_LOCAL;
}
break;
}
if (!rb_enc_isdigit(*m, enc)) {
while (m <= name + last && is_identchar(m, e, enc)) {
@ -10444,7 +10449,7 @@ intern_str(VALUE str)
}
}
}
if (m - name < len) id = ID_JUNK;
if (id != ID_ATTRSET && m - name < len) id = ID_JUNK;
if (sym_check_asciionly(str)) symenc = rb_usascii_encoding();
new_id:
if (symenc != enc) rb_enc_associate(str, symenc);
@ -10527,16 +10532,21 @@ rb_id2str(ID id)
}
if (is_attrset_id(id)) {
ID id2 = (id & ~ID_SCOPE_MASK) | ID_LOCAL;
ID id_stem = (id & ~ID_SCOPE_MASK);
VALUE str;
while (!(str = rb_id2str(id2))) {
if (!is_local_id(id2)) return 0;
id2 = (id & ~ID_SCOPE_MASK) | ID_CONST;
}
do {
if (!!(str = rb_id2str(id_stem | ID_LOCAL))) break;
if (!!(str = rb_id2str(id_stem | ID_CONST))) break;
if (!!(str = rb_id2str(id_stem | ID_INSTANCE))) break;
if (!!(str = rb_id2str(id_stem | ID_GLOBAL))) break;
if (!!(str = rb_id2str(id_stem | ID_CLASS))) break;
if (!!(str = rb_id2str(id_stem | ID_JUNK))) break;
return 0;
} while (0);
str = rb_str_dup(str);
rb_str_cat(str, "=", 1);
rb_intern_str(str);
register_symid_str(id, str);
if (st_lookup(global_symbols.id_str, id, &data)) {
VALUE str = (VALUE)data;
if (RBASIC(str)->klass == 0)

View file

@ -132,6 +132,10 @@ class TestStruct < Test::Unit::TestCase
klass = Struct.new(:@a)
o = klass.new(1)
assert_equal("#<struct :@a=1>", o.inspect)
methods = klass.instance_methods(false)
assert_equal([:@a, :"@a="].inspect, methods.inspect, '[Bug #8756]')
assert_include(methods, :@a)
assert_include(methods, :"@a=")
end
def test_init_copy