From 6fe9b2b79446e20e4a3a48c898313c63258182d5 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 29 Oct 2014 14:24:24 +0000 Subject: [PATCH] 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 --- parse.y | 7 ++++++- test/ruby/test_syntax.rb | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/parse.y b/parse.y index b256633189..da91b53a02 100644 --- a/parse.y +++ b/parse.y @@ -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)); diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index 2da7797b47..55af33fe48 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -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