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

Make circular argument reference a SyntaxError instead of a warning

Fixes [Bug #10314]
This commit is contained in:
Jeremy Evans 2019-08-11 16:22:58 -07:00
parent fdfb5100b9
commit 0162e7e647
Notes: git 2019-10-18 01:32:31 +09:00
5 changed files with 99 additions and 54 deletions

View file

@ -267,20 +267,38 @@ describe "A lambda literal -> () { }" do
end
describe "with circular optional argument reference" do
it "shadows an existing local with the same name as the argument" do
a = 1
-> {
@proc = eval "-> (a=a) { a }"
}.should complain(/circular argument reference/)
@proc.call.should == nil
ruby_version_is ''...'2.7' do
it "warns and uses a nil value when there is an existing local variable with same name" do
a = 1
-> {
@proc = eval "-> (a=a) { a }"
}.should complain(/circular argument reference/)
@proc.call.should == nil
end
it "warns and uses a nil value when there is an existing method with same name" do
def a; 1; end
-> {
@proc = eval "-> (a=a) { a }"
}.should complain(/circular argument reference/)
@proc.call.should == nil
end
end
it "shadows an existing method with the same name as the argument" do
def a; 1; end
-> {
@proc = eval "-> (a=a) { a }"
}.should complain(/circular argument reference/)
@proc.call.should == nil
ruby_version_is '2.7' do
it "raises a SyntaxError if using an existing local with the same name as the argument" do
a = 1
-> {
@proc = eval "-> (a=a) { a }"
}.should raise_error(SyntaxError)
end
it "raises a SyntaxError if there is an existing method with the same name as the argument" do
def a; 1; end
-> {
@proc = eval "-> (a=a) { a }"
}.should raise_error(SyntaxError)
end
end
it "calls an existing method with the same name as the argument if explicitly using ()" do