ruby-changes:36108
From: nobu <ko1@a...>
Date: Wed, 29 Oct 2014 23:24:40 +0900 (JST)
Subject: [ruby-changes:36108] nobu:r48189 (trunk): parse.y: warn iside a block
nobu 2014-10-29 23:24:24 +0900 (Wed, 29 Oct 2014) New Revision: 48189 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48189 Log: parse.y: warn iside a block * parse.y (gettable_gen): also warn circular argument reference even inside a block. [ruby-core:65990] [Bug #10314] Modified files: trunk/parse.y trunk/test/ruby/test_syntax.rb Index: parse.y =================================================================== --- parse.y (revision 48188) +++ parse.y (revision 48189) @@ -8733,7 +8733,12 @@ gettable_gen(struct parser_params *parse https://github.com/ruby/ruby/blob/trunk/parse.y#L8733 } 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)); Index: test/ruby/test_syntax.rb =================================================================== --- test/ruby/test_syntax.rb (revision 48188) +++ test/ruby/test_syntax.rb (revision 48189) @@ -151,6 +151,26 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L151 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L187 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/