1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2014-05-06 14:29:07 +00:00
parent d750b62d66
commit b5cae3820b
3 changed files with 22 additions and 5 deletions

View file

@ -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.

16
parse.y
View file

@ -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);
}

View file

@ -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