summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--parse.y29
-rw-r--r--test/ruby/test_struct.rb8
3 files changed, 29 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog
index 73e1f9e094..9061b20f3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sun Aug 11 15:10:40 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (rb_enc_symname_type): allow ID_ATTRSET for ID_INSTANCE,
+ ID_GLOBAL, ID_CLASS, ID_JUNK too. [Bug #8756]
+
Sun Aug 11 13:17:00 2013 Charlie Somerville <charliesome@ruby-lang.org>
* include/ruby/encoding.h: Reduce ENCODING_INLINE_MAX to 127 as this
diff --git a/parse.y b/parse.y
index f5e79c18e7..060691f7b7 100644
--- a/parse.y
+++ b/parse.y
@@ -10182,8 +10182,11 @@ rb_enc_symname_p(const char *name, rb_encoding *enc)
return rb_enc_symname2_p(name, strlen(name), enc);
}
+#define IDSET_ATTRSET_FOR_SYNTAX ((1U<<ID_LOCAL)|(1U<<ID_CONST))
+#define IDSET_ATTRSET_FOR_INTERN (~(~0U<<ID_SCOPE_MASK) & ~(1U<<ID_ATTRSET))
+
static int
-rb_enc_symname_type(const char *name, long len, rb_encoding *enc)
+rb_enc_symname_type(const char *name, long len, rb_encoding *enc, unsigned int allowed_atttset)
{
const char *m = name;
const char *e = m + len;
@@ -10267,7 +10270,7 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc)
++m;
break;
case '=':
- if (type != ID_CONST && type != ID_LOCAL) return -1;
+ if (!(allowed_atttset & (1U << type))) return -1;
type = ID_ATTRSET;
++m;
break;
@@ -10280,15 +10283,15 @@ rb_enc_symname_type(const char *name, long len, rb_encoding *enc)
int
rb_enc_symname2_p(const char *name, long len, rb_encoding *enc)
{
- return rb_enc_symname_type(name, len, enc) != -1;
+ return rb_enc_symname_type(name, len, enc, IDSET_ATTRSET_FOR_SYNTAX) != -1;
}
static int
-rb_str_symname_type(VALUE name)
+rb_str_symname_type(VALUE name, unsigned int allowed_atttset)
{
const char *ptr = StringValuePtr(name);
long len = RSTRING_LEN(name);
- int type = rb_enc_symname_type(ptr, len, rb_enc_get(name));
+ int type = rb_enc_symname_type(ptr, len, rb_enc_get(name), allowed_atttset);
RB_GC_GUARD(name);
return type;
}
@@ -10719,43 +10722,43 @@ rb_check_id_cstr(const char *ptr, long len, rb_encoding *enc)
int
rb_is_const_name(VALUE name)
{
- return rb_str_symname_type(name) == ID_CONST;
+ return rb_str_symname_type(name, 0) == ID_CONST;
}
int
rb_is_class_name(VALUE name)
{
- return rb_str_symname_type(name) == ID_CLASS;
+ return rb_str_symname_type(name, 0) == ID_CLASS;
}
int
rb_is_global_name(VALUE name)
{
- return rb_str_symname_type(name) == ID_GLOBAL;
+ return rb_str_symname_type(name, 0) == ID_GLOBAL;
}
int
rb_is_instance_name(VALUE name)
{
- return rb_str_symname_type(name) == ID_INSTANCE;
+ return rb_str_symname_type(name, 0) == ID_INSTANCE;
}
int
rb_is_attrset_name(VALUE name)
{
- return rb_str_symname_type(name) == ID_ATTRSET;
+ return rb_str_symname_type(name, IDSET_ATTRSET_FOR_INTERN) == ID_ATTRSET;
}
int
rb_is_local_name(VALUE name)
{
- return rb_str_symname_type(name) == ID_LOCAL;
+ return rb_str_symname_type(name, 0) == ID_LOCAL;
}
int
rb_is_method_name(VALUE name)
{
- switch (rb_str_symname_type(name)) {
+ switch (rb_str_symname_type(name, 0)) {
case ID_LOCAL: case ID_ATTRSET: case ID_JUNK:
return TRUE;
}
@@ -10765,7 +10768,7 @@ rb_is_method_name(VALUE name)
int
rb_is_junk_name(VALUE name)
{
- return rb_str_symname_type(name) == -1;
+ return rb_str_symname_type(name, IDSET_ATTRSET_FOR_SYNTAX) == -1;
}
#endif /* !RIPPER */
diff --git a/test/ruby/test_struct.rb b/test/ruby/test_struct.rb
index 677452879c..1bcc485410 100644
--- a/test/ruby/test_struct.rb
+++ b/test/ruby/test_struct.rb
@@ -131,7 +131,15 @@ class TestStruct < Test::Unit::TestCase
klass = Struct.new(:@a)
o = klass.new(1)
+ assert_equal(1, o.__send__(:@a))
assert_equal("#<struct :@a=1>", o.inspect)
+ o.__send__(:"@a=", 2)
+ assert_equal(2, o.__send__(:@a))
+ assert_equal("#<struct :@a=2>", o.inspect)
+ o.__send__("@a=", 3)
+ assert_equal(3, o.__send__(:@a))
+ assert_equal("#<struct :@a=3>", o.inspect)
+
methods = klass.instance_methods(false)
assert_equal([:@a, :"@a="].inspect, methods.inspect, '[Bug #8756]')
assert_include(methods, :@a)