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

parse.y: warn reference after method definition

* parse.y (primary): restore current_arg so that circular
  reference after a method definition is also warned.
  [ruby-core:61299] [Bug #9593]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2014-12-14 11:11:45 +00:00
parent db4e9d5eb3
commit 2de3281af4
3 changed files with 20 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Sun Dec 14 20:11:42 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* parse.y (primary): restore current_arg so that circular
reference after a method definition is also warned.
[ruby-core:61299] [Bug #9593]
Sat Dec 13 20:41:55 2014 Nobuyoshi Nakada <nobu@ruby-lang.org> Sat Dec 13 20:41:55 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt * vm_trace.c (rb_postponed_job_flush): mask signal trap interrupt

View file

@ -3027,12 +3027,15 @@ primary : literal
%*/ %*/
local_pop(); local_pop();
in_def--; in_def--;
current_arg = $<id>3;
} }
| k_def singleton dot_or_colon {lex_state = EXPR_FNAME;} fname | k_def singleton dot_or_colon {lex_state = EXPR_FNAME;} fname
{ {
in_single++; in_single++;
lex_state = EXPR_ENDFN; /* force for args */ lex_state = EXPR_ENDFN; /* force for args */
local_push(0); local_push(0);
$<id>$ = current_arg;
current_arg = 0;
} }
f_arglist f_arglist
bodystmt bodystmt
@ -3048,6 +3051,7 @@ primary : literal
%*/ %*/
local_pop(); local_pop();
in_single--; in_single--;
current_arg = $<id>6;
} }
| keyword_break | keyword_break
{ {

View file

@ -202,6 +202,16 @@ class TestSyntax < Test::Unit::TestCase
o.instance_eval("def foo(var = bar {var}) var end") o.instance_eval("def foo(var = bar {var}) var end")
end end
o = Object.new
assert_warn(/circular argument reference - var/) do
o.instance_eval("def foo(var = (def bar;end; var)) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
o.instance_eval("def foo(var = (def self.bar;end; var)) var end")
end
o = Object.new o = Object.new
assert_warn("") do assert_warn("") do
o.instance_eval("def foo(var = bar {|var| var}) var end") o.instance_eval("def foo(var = bar {|var| var}) var end")