зеркало из https://github.com/github/ruby.git
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:
Родитель
98ea627561
Коммит
6fe9b2b794
7
parse.y
7
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));
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче