From 89486c79bb59216dbbbdff69a2c81cb387f64c5f Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 31 May 2024 08:22:40 -0700 Subject: Make error messages clear blocks/keywords are disallowed in index assignment Blocks and keywords are allowed in regular index. Also update NEWS to make this more clear. Co-authored-by: Nobuyoshi Nakada --- test/ruby/test_call.rb | 6 +++--- test/ruby/test_parse.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index a52b75c267..ced1eaf5e9 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -136,7 +136,7 @@ class TestCall < Test::Unit::TestCase # Prevent "assigned but unused variable" warnings _ = [h, a, kw, b] - message = /keyword arg given in index/ + message = /keyword arg given in index assignment/ # +=, without block, non-popped assert_syntax_error(%q{h[**kw] += 1}, message) @@ -270,7 +270,7 @@ class TestCall < Test::Unit::TestCase def o.[](...) 2 end def o.[]=(...) end - message = /keyword arg given in index/ + message = /keyword arg given in index assignment/ assert_syntax_error(%q{o[kw: 1] += 1}, message) assert_syntax_error(%q{o[**o] += 1}, message) @@ -292,7 +292,7 @@ class TestCall < Test::Unit::TestCase def []=(*a, **b) @set = [a, b] end end.new - message = /keyword arg given in index/ + message = /keyword arg given in index assignment/ a = [] kw = {} diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index 3857f3cc17..20364c5a0d 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -512,12 +512,12 @@ class TestParse < Test::Unit::TestCase def t.dummy(_) end - assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index/) + assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index assignment/) begin; t[42, &blk] ||= 42 end; - assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index/) + assert_syntax_error("#{<<~"begin;"}\n#{<<~'end;'}", /block arg given in index assignment/) begin; t[42, &blk] ||= t.dummy 42 # command_asgn test end; -- cgit v1.2.3