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

parse.y: warn iside a block

* parse.y (gettable_gen): also warn circular argument reference even
  inside a block.  [ruby-core:65990] [Bug #10314]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48189 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-10-29 14:24:24 +00:00
parent 98ea627561
commit 6fe9b2b794
2 changed files with 46 additions and 1 deletions

View file

@ -8733,7 +8733,12 @@ gettable_gen(struct parser_params *parser, ID id)
}
switch (id_type(id)) {
case ID_LOCAL:
if (dyna_in_block() && dvar_defined(id)) return NEW_DVAR(id);
if (dyna_in_block() && dvar_defined(id)) {
if (id == current_arg) {
rb_warnV("circular argument reference - %"PRIsVALUE, rb_id2str(id));
}
return NEW_DVAR(id);
}
if (local_id(id)) {
if (id == current_arg) {
rb_warnV("circular argument reference - %"PRIsVALUE, rb_id2str(id));

View file

@ -151,6 +151,26 @@ class TestSyntax < Test::Unit::TestCase
o.instance_eval("def foo(var: var) var end")
end
assert_nil(o.foo, bug9593)
o = Object.new
assert_warn(/circular argument reference - var/) do
o.instance_eval("def foo(var: bar(var)) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
o.instance_eval("def foo(var: bar {var}) var end")
end
o = Object.new
assert_warn("") do
o.instance_eval("def foo(var: bar {|var| var}) var end")
end
o = Object.new
assert_warn("") do
o.instance_eval("def foo(var: def bar(var) var; end) var end")
end
end
def test_optional_self_reference
@ -167,6 +187,26 @@ class TestSyntax < Test::Unit::TestCase
o.instance_eval("def foo(var = var) var end")
end
assert_nil(o.foo, bug9593)
o = Object.new
assert_warn(/circular argument reference - var/) do
o.instance_eval("def foo(var = bar(var)) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
o.instance_eval("def foo(var = bar {var}) var end")
end
o = Object.new
assert_warn("") do
o.instance_eval("def foo(var = bar {|var| var}) var end")
end
o = Object.new
assert_warn("") do
o.instance_eval("def foo(var = def bar(var) var; end) var end")
end
end
def test_warn_grouped_expression