diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-06 14:29:07 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-05-06 14:29:07 +0000 |
commit | b5cae3820b48d2208131ecc7ca442de6ad528e4c (patch) | |
tree | 5a1ccb3d3b98f3b75df16729ac82a12283725b16 | |
parent | d750b62d66d812c3c946ce74be60e5b2c890d474 (diff) | |
download | ruby-b5cae3820b48d2208131ecc7ca442de6ad528e4c.tar.gz |
parse.y: no duplicated names
* parse.y (new_bv_gen): no duplicated names, if already added in
shadowing_lvar().
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | parse.y | 16 | ||||
-rw-r--r-- | test/ruby/test_variable.rb | 6 |
3 files changed, 22 insertions, 5 deletions
@@ -1,4 +1,7 @@ -Tue May 6 23:28:47 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> +Tue May 6 23:29:05 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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. @@ -8761,10 +8761,10 @@ is_private_local_id(ID name) #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 *parser, ID name) 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 *parser, ID name) 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, ID name) rb_id2name(name)); return; } - shadowing_lvar(name); + if (!shadowing_lvar_0(parser, name)) return; dyna_var(name); } diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb index 89f1d58348..e6730f858f 100644 --- a/test/ruby/test_variable.rb +++ b/test/ruby/test_variable.rb @@ -89,6 +89,12 @@ class TestVariable < Test::Unit::TestCase 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 |