diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-08-11 16:22:58 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-10-17 09:32:06 -0700 |
commit | 0162e7e6471b639dfeeded29943e9e27c9519826 (patch) | |
tree | 7d3a205ed67f999bda5ffd755287a318a7e5fc88 /spec | |
parent | fdfb5100b9e74cfb89b6de3649e98cb1ad85497a (diff) |
Make circular argument reference a SyntaxError instead of a warning
Fixes [Bug #10314]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/2569
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 42 | ||||
-rw-r--r-- | spec/ruby/language/def_spec.rb | 35 | ||||
-rw-r--r-- | spec/ruby/language/lambda_spec.rb | 42 |
3 files changed, 85 insertions, 34 deletions
diff --git a/spec/ruby/language/block_spec.rb b/spec/ruby/language/block_spec.rb index e5c9fcb762..6f92383af8 100644 --- a/spec/ruby/language/block_spec.rb +++ b/spec/ruby/language/block_spec.rb @@ -876,20 +876,38 @@ describe "Post-args" do end describe "with a circular argument reference" do - it "shadows an existing local with the same name as the argument" do - a = 1 - -> { - @proc = eval "proc { |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 "proc { |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 "proc { |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 "proc { |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 "proc { |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 "proc { |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 diff --git a/spec/ruby/language/def_spec.rb b/spec/ruby/language/def_spec.rb index 82813bd36c..fc5693a2f0 100644 --- a/spec/ruby/language/def_spec.rb +++ b/spec/ruby/language/def_spec.rb @@ -177,17 +177,32 @@ describe "An instance method with a default argument" do foo(2,3,3).should == [2,3,[3]] end - it "shadows an existing method with the same name as the local" do - def bar - 1 + ruby_version_is ''...'2.7' do + it "warns and uses a nil value when there is an existing local method with same name" do + def bar + 1 + end + -> { + eval "def foo(bar = bar) + bar + end" + }.should complain(/circular argument reference/) + foo.should == nil + foo(2).should == 2 + end + end + + ruby_version_is '2.7' do + it "raises a syntaxError an existing method with the same name as the local variable" do + def bar + 1 + end + -> { + eval "def foo(bar = bar) + bar + end" + }.should raise_error(SyntaxError) end - -> { - eval "def foo(bar = bar) - bar - end" - }.should complain(/circular argument reference/) - foo.should == nil - foo(2).should == 2 end it "calls a method with the same name as the local when explicitly using ()" do diff --git a/spec/ruby/language/lambda_spec.rb b/spec/ruby/language/lambda_spec.rb index 5fa7fa6bfa..ddd0b574b3 100644 --- a/spec/ruby/language/lambda_spec.rb +++ b/spec/ruby/language/lambda_spec.rb @@ -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 |