Project

General

Profile

Bug #10314 ยป circular-arg-ref-syntax-error-10314.patch

jeremyevans0 (Jeremy Evans), 08/11/2019 11:26 PM

View differences:

parse.y
case ID_LOCAL:
if (dyna_in_block(p) && dvar_defined_ref(p, id, &vidp)) {
if (id == p->cur_arg) {
rb_warn1("circular argument reference - %"PRIsWARN, rb_id2str(id));
compile_error(p, "circular argument reference - %"PRIsWARN, rb_id2str(id));
return 0;
}
if (vidp) *vidp |= LVAR_USED;
node = NEW_DVAR(id, loc);
......
}
if (local_id_ref(p, id, &vidp)) {
if (id == p->cur_arg) {
rb_warn1("circular argument reference - %"PRIsWARN, rb_id2str(id));
compile_error(p, "circular argument reference - %"PRIsWARN, rb_id2str(id));
return 0;
}
if (vidp) *vidp |= LVAR_USED;
node = NEW_LVAR(id, loc);
test/ruby/test_syntax.rb
end
def test_keyword_self_reference
bug9593 = '[ruby-core:61299] [Bug #9593]'
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
o.instance_eval("def foo(var: defined?(var)) var end")
end
assert_equal(42, o.foo(var: 42))
assert_equal("local-variable", o.foo, bug9593)
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
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
assert_raise(SyntaxError) do
o.instance_eval("def foo(var: bar(var)) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
o.instance_eval("def foo(var: bar {var}) var end")
end
......
end
def test_optional_self_reference
bug9593 = '[ruby-core:61299] [Bug #9593]'
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
o.instance_eval("def foo(var = defined?(var)) var end")
end
assert_equal(42, o.foo(42))
assert_equal("local-variable", o.foo, bug9593)
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
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
assert_raise(SyntaxError) do
o.instance_eval("def foo(var = bar(var)) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
o.instance_eval("def foo(var = bar {var}) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
o.instance_eval("def foo(var = (def bar;end; var)) var end")
end
o = Object.new
assert_warn(/circular argument reference - var/) do
assert_raise(SyntaxError) do
o.instance_eval("def foo(var = (def self.bar;end; var)) var end")
end
    (1-1/1)