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/ruby/language/block_spec.rb | |
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/ruby/language/block_spec.rb')
-rw-r--r-- | spec/ruby/language/block_spec.rb | 42 |
1 files changed, 30 insertions, 12 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 |