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

ruby-changes:33765

From: nobu <ko1@a...>
Date: Tue, 6 May 2014 23:29:15 +0900 (JST)
Subject: [ruby-changes:33765] nobu:r45846 (trunk): parse.y: no duplicated names

nobu	2014-05-06 23:29:07 +0900 (Tue, 06 May 2014)

  New Revision: 45846

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

  Log:
    parse.y: no duplicated names
    
    * parse.y (new_bv_gen): no duplicated names, if already added in
      shadowing_lvar().

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/test/ruby/test_variable.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45845)
+++ ChangeLog	(revision 45846)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Tue May  6 23:28:47 2014  Nobuyoshi Nakada  <nobu@r...>
+Tue May  6 23:29:05 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* parse.y (new_bv_gen): no duplicated names, if already added in
+	  shadowing_lvar().
 
 	* parse.y (local_tbl_gen): remove local variables duplicated with
 	  arguments.
Index: parse.y
===================================================================
--- parse.y	(revision 45845)
+++ parse.y	(revision 45846)
@@ -8761,10 +8761,10 @@ is_private_local_id(ID name) https://github.com/ruby/ruby/blob/trunk/parse.y#L8761
 
 #define LVAR_USED ((ID)1 << (sizeof(ID) * CHAR_BIT - 1))
 
-static ID
-shadowing_lvar_gen(struct parser_params *parser, ID name)
+static int
+shadowing_lvar_0(struct parser_params *parser, ID name)
 {
-    if (is_private_local_id(name)) return name;
+    if (is_private_local_id(name)) return 1;
     if (dyna_in_block()) {
 	if (dvar_curr(name)) {
 	    yyerror("duplicated argument name");
@@ -8775,6 +8775,7 @@ shadowing_lvar_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L8775
 	    if (lvtbl->used) {
 		vtable_add(lvtbl->used, (ID)ruby_sourceline | LVAR_USED);
 	    }
+	    return 0;
 	}
     }
     else {
@@ -8782,6 +8783,13 @@ shadowing_lvar_gen(struct parser_params https://github.com/ruby/ruby/blob/trunk/parse.y#L8783
 	    yyerror("duplicated argument name");
 	}
     }
+    return 1;
+}
+
+static ID
+shadowing_lvar_gen(struct parser_params *parser, ID name)
+{
+    shadowing_lvar_0(parser, name);
     return name;
 }
 
@@ -8794,7 +8802,7 @@ new_bv_gen(struct parser_params *parser, https://github.com/ruby/ruby/blob/trunk/parse.y#L8802
 		      rb_id2name(name));
 	return;
     }
-    shadowing_lvar(name);
+    if (!shadowing_lvar_0(parser, name)) return;
     dyna_var(name);
 }
 
Index: test/ruby/test_variable.rb
===================================================================
--- test/ruby/test_variable.rb	(revision 45845)
+++ test/ruby/test_variable.rb	(revision 45846)
@@ -89,6 +89,12 @@ class TestVariable < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_variable.rb#L89
     assert_equal([:x, :bug9486, :x], x)
   end
 
+  def test_shadowing_block_local_variables
+    bug9486 = '[ruby-core:60501] [Bug #9486]'
+    x = tap {|;x| break local_variables}
+    assert_equal([:x, :bug9486, :x], x)
+  end
+
   def local_variables_of(bind)
     this_should_not_be_in_bind = 2
     bind.local_variables

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

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