[前][次][番号順一覧][スレッド一覧]

ruby-changes:31004

From: nobu <ko1@a...>
Date: Sun, 29 Sep 2013 22:56:40 +0900 (JST)
Subject: [ruby-changes:31004] nobu:r43083 (trunk): parse.y: fix inconsistency with literals

nobu	2013-09-29 22:56:33 +0900 (Sun, 29 Sep 2013)

  New Revision: 43083

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43083

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/-test-/symbol/type.c
    trunk/parse.y
    trunk/test/-ext-/symbol/test_type.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43082)
+++ ChangeLog	(revision 43083)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Sep 29 22:56:31 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
+
+	* 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@c...>
 
 	* vm_insnhelper.c (vm_callee_setup_arg_complex, vm_yield_setup_block_args):
Index: parse.y
===================================================================
--- parse.y	(revision 43082)
+++ parse.y	(revision 43083)
@@ -8885,17 +8885,23 @@ ID https://github.com/ruby/ruby/blob/trunk/parse.y#L8885
 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));
 
 	}
     }
Index: ext/-test-/symbol/type.c
===================================================================
--- ext/-test-/symbol/type.c	(revision 43082)
+++ ext/-test-/symbol/type.c	(revision 43083)
@@ -27,8 +27,17 @@ bug_sym_##type##_p(VALUE self, VALUE nam https://github.com/ruby/ruby/blob/trunk/ext/-test-/symbol/type.c#L27
 
 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);
 }
Index: test/-ext-/symbol/test_type.rb
===================================================================
--- test/-ext-/symbol/test_type.rb	(revision 43082)
+++ test/-ext-/symbol/test_type.rb	(revision 43083)
@@ -91,6 +91,19 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_type.rb#L91
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]