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

ruby-changes:35089

From: nobu <ko1@a...>
Date: Wed, 13 Aug 2014 21:20:20 +0900 (JST)
Subject: [ruby-changes:35089] nobu:r47171 (trunk): parse.y: preserve encodings

nobu	2014-08-13 21:20:13 +0900 (Wed, 13 Aug 2014)

  New Revision: 47171

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

  Log:
    parse.y: preserve encodings
    
    * parse.y (shadowing_lvar, warn_unused_var),
      (reg_named_capture_assign_iter): preserve encodings in warning
      messages.

  Modified files:
    trunk/parse.y
    trunk/test/ruby/test_parse.rb
Index: parse.y
===================================================================
--- parse.y	(revision 47170)
+++ parse.y	(revision 47171)
@@ -165,7 +165,7 @@ vtable_add(struct vtable *tbl, ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L165
     if (!POINTER_P(tbl)) {
         rb_bug("vtable_add: vtable is not allocated (%p)", (void *)tbl);
     }
-    if (VTBL_DEBUG) printf("vtable_add: %p, %s\n", (void *)tbl, rb_id2name(id));
+    if (VTBL_DEBUG) printf("vtable_add: %p, %"PRIsVALUE"\n", (void *)tbl, rb_id2str(id));
 
     if (tbl->pos == tbl->capa) {
         tbl->capa = tbl->capa * 2;
@@ -8660,7 +8660,7 @@ gettable_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8660
       case ID_CLASS:
 	return NEW_CVAR(id);
     }
-    compile_error(PARSER_ARG "identifier %s is not valid to get", rb_id2name(id));
+    compile_error(PARSER_ARG "identifier %"PRIsVALUE" is not valid to get", rb_id2str(id));
     return 0;
 }
 #else  /* !RIPPER */
@@ -8678,7 +8678,7 @@ id_is_var_gen(struct parser_params *pars https://github.com/ruby/ruby/blob/trunk/parse.y#L8678
 	    return 0;
 	}
     }
-    compile_error(PARSER_ARG "identifier %s is not valid to get", rb_id2name(id));
+    compile_error(PARSER_ARG "identifier %s is not valid to get", rb_id2str(id));
     return 0;
 }
 #endif /* !RIPPER */
@@ -8774,7 +8774,7 @@ assignable_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L8774
       case ID_CLASS:
 	return assignable_result(NEW_CVASGN(id, val));
       default:
-	compile_error(PARSER_ARG "identifier %s is not valid to set", rb_id2name(id));
+	compile_error(PARSER_ARG "identifier %"PRIsVALUE" is not valid to set", rb_id2str(id));
     }
   error:
     return assignable_result(0);
@@ -8804,7 +8804,7 @@ shadowing_lvar_0(struct parser_params *p https://github.com/ruby/ruby/blob/trunk/parse.y#L8804
 	    yyerror("duplicated argument name");
 	}
 	else if (dvar_defined_get(name) || local_id(name)) {
-	    rb_warningS("shadowing outer local variable - %s", rb_id2name(name));
+	    rb_warningS("shadowing outer local variable - %"PRIsVALUE, rb_id2str(name));
 	    vtable_add(lvtbl->vars, name);
 	    if (lvtbl->used) {
 		vtable_add(lvtbl->used, (ID)ruby_sourceline | LVAR_USED);
@@ -8832,8 +8832,8 @@ new_bv_gen(struct parser_params *parser, https://github.com/ruby/ruby/blob/trunk/parse.y#L8832
 {
     if (!name) return;
     if (!is_local_id(name)) {
-	compile_error(PARSER_ARG "invalid local variable - %s",
-		      rb_id2name(name));
+	compile_error(PARSER_ARG "invalid local variable - %"PRIsVALUE,
+		      rb_id2str(name));
 	return;
     }
     if (!shadowing_lvar_0(parser, name)) return;
@@ -9659,7 +9659,7 @@ warn_unused_var(struct parser_params *pa https://github.com/ruby/ruby/blob/trunk/parse.y#L9659
     for (i = 0; i < cnt; ++i) {
 	if (!v[i] || (u[i] & LVAR_USED)) continue;
 	if (is_private_local_id(v[i])) continue;
-	rb_warn4S(ruby_sourcefile, (int)u[i], "assigned but unused variable - %s", rb_id2name(v[i]));
+	rb_warn4S(ruby_sourcefile, (int)u[i], "assigned but unused variable - %"PRIsVALUE, rb_id2str(v[i]));
     }
 }
 
@@ -9938,8 +9938,8 @@ reg_named_capture_assign_iter(const Onig https://github.com/ruby/ruby/blob/trunk/parse.y#L9938
     }
     var = intern_cstr_without_pindown(s, len, enc);
     if (dvar_defined(var) || local_id(var)) {
-        rb_warningS("named capture conflicts a local variable - %s",
-                    rb_id2name(var));
+        rb_warningS("named capture conflicts a local variable - %"PRIsVALUE,
+                    rb_id2str(var));
     }
     arg->succ_block = block_append(arg->succ_block,
         newline_node(node_assign(assignable(var,0),
@@ -10576,8 +10576,7 @@ ripper_id2sym(ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L10576
         name = "&&";
         break;
       default:
-        name = rb_id2name(id);
-        if (!name) {
+        if (!rb_id2str(id)) {
             rb_bug("cannot convert ID to string: %ld", (unsigned long)id);
         }
         return ID2SYM(id);
Index: test/ruby/test_parse.rb
===================================================================
--- test/ruby/test_parse.rb	(revision 47170)
+++ test/ruby/test_parse.rb	(revision 47171)
@@ -854,15 +854,21 @@ x = __ENCODING__ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_parse.rb#L854
 
   def test_shadowing_variable
     assert_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")}
+    a = "\u{3042}"
+    assert_warning(/#{a}/o) {eval("#{a}=1; tap {|#{a}|}")}
   end
 
   def test_unused_variable
     o = Object.new
     assert_warning(/assigned but unused variable/) {o.instance_eval("def foo; a=1; nil; end")}
+    a = "\u{3042}"
+    assert_warning(/#{a}/) {o.instance_eval("def foo; #{a}=1; nil; end")}
   end
 
   def test_named_capture_conflict
     a = 1
     assert_warning(/named capture conflict/) {eval("a = 1; /(?<a>)/ =~ ''")}
+    a = "\u{3042}"
+    assert_warning(/#{a}/) {eval("#{a} = 1; /(?<#{a}>)/ =~ ''")}
   end
 end

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

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