mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Private local variables should shadow outer variables [Bug #18629]
This commit is contained in:
parent
ee48c9cda6
commit
3ddf6ad4d2
2 changed files with 6 additions and 1 deletions
3
parse.y
3
parse.y
|
@ -10994,9 +10994,9 @@ is_private_local_id(ID name)
|
|||
static int
|
||||
shadowing_lvar_0(struct parser_params *p, ID name)
|
||||
{
|
||||
if (is_private_local_id(name)) return 1;
|
||||
if (dyna_in_block(p)) {
|
||||
if (dvar_curr(p, name)) {
|
||||
if (is_private_local_id(name)) return 1;
|
||||
yyerror0("duplicated argument name");
|
||||
}
|
||||
else if (dvar_defined(p, name) || local_id(p, name)) {
|
||||
|
@ -11009,6 +11009,7 @@ shadowing_lvar_0(struct parser_params *p, ID name)
|
|||
}
|
||||
else {
|
||||
if (local_id(p, name)) {
|
||||
if (is_private_local_id(name)) return 1;
|
||||
yyerror0("duplicated argument name");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -930,6 +930,10 @@ x = __ENCODING__
|
|||
assert_no_warning(/shadowing outer local variable/) {eval("a=1; tap {|a|}")}
|
||||
end
|
||||
|
||||
def test_shadowing_private_local_variable
|
||||
assert_equal 1, eval("_ = 1; [[2]].each{ |(_)| }; _")
|
||||
end
|
||||
|
||||
def test_unused_variable
|
||||
o = Object.new
|
||||
assert_warning(/assigned but unused variable/) {o.instance_eval("def foo; a=1; nil; end")}
|
||||
|
|
Loading…
Add table
Reference in a new issue