diff --git a/bootstraptest/test_method.rb b/bootstraptest/test_method.rb index 964bf39d98b801..1509a8d32d67c5 100644 --- a/bootstraptest/test_method.rb +++ b/bootstraptest/test_method.rb @@ -340,24 +340,6 @@ def method_missing(mid, *args, &block) block end assert_equal '1', %q( class C; def m() 1 end; private :m end C.new.send(:m) ) -# with block -assert_equal '[[:ok1, :foo], [:ok2, :foo, :bar]]', -%q{ - class C - def [](a) - $ary << [yield, a] - end - def []=(a, b) - $ary << [yield, a, b] - end - end - - $ary = [] - C.new[:foo, &lambda{:ok1}] - C.new[:foo, &lambda{:ok2}] = :bar - $ary -} - # with assert_equal '[:ok1, [:ok2, 11]]', %q{ class C @@ -404,7 +386,6 @@ def m(*args, &b) # aset and splat assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;Foo.new[1,*a=[2,3]]=4} -assert_equal '4', %q{class Foo;def []=(a,b,c,d);end;end;def m(&blk)Foo.new[1,*a=[2,3],&blk]=4;end;m{}} # post test assert_equal %q{[1, 2, :o1, :o2, [], 3, 4, NilClass, nil, nil]}, %q{ diff --git a/parse.y b/parse.y index a712ca6a6eb5de..e8935b6988a6f5 100644 --- a/parse.y +++ b/parse.y @@ -13875,6 +13875,9 @@ new_bv(struct parser_params *p, ID name) static NODE * aryset(struct parser_params *p, NODE *recv, NODE *idx, const YYLTYPE *loc) { + if (idx && nd_type_p(idx, NODE_BLOCK_PASS)) { + compile_error(p, "block arg given in index"); + } return NEW_ATTRASGN(recv, tASET, idx, loc); } diff --git a/test/prism/fixtures/arrays.txt b/test/prism/fixtures/arrays.txt index cd4e3046f78f3a..6cb0c25e608f46 100644 --- a/test/prism/fixtures/arrays.txt +++ b/test/prism/fixtures/arrays.txt @@ -81,13 +81,13 @@ foo[bar] = baz %w[\C:] -foo[&bar] = 1 +# foo[&bar] = 1 -foo.foo[&bar] = 1 +# foo.foo[&bar] = 1 -def foo(&) - bar[&] = 1 -end +# def foo(&) +# bar[&] = 1 +# end foo[] += 1 diff --git a/test/prism/snapshots/arrays.txt b/test/prism/snapshots/arrays.txt index 1cf6b2269722df..a2392f37e26113 100644 --- a/test/prism/snapshots/arrays.txt +++ b/test/prism/snapshots/arrays.txt @@ -2,7 +2,7 @@ ├── locals: [] └── statements: @ StatementsNode (location: (1,0)-(142,32)) - └── body: (length: 59) + └── body: (length: 56) ├── @ ArrayNode (location: (1,0)-(1,4)) │ ├── flags: contains_splat │ ├── elements: (length: 1) @@ -942,151 +942,6 @@ │ │ └── unescaped: "\\C:" │ ├── opening_loc: (82,0)-(82,3) = "%w[" │ └── closing_loc: (82,6)-(82,7) = "]" - ├── @ CallNode (location: (84,0)-(84,13)) - │ ├── flags: attribute_write - │ ├── receiver: - │ │ @ CallNode (location: (84,0)-(84,3)) - │ │ ├── flags: variable_call, ignore_visibility - │ │ ├── receiver: ∅ - │ │ ├── call_operator_loc: ∅ - │ │ ├── name: :foo - │ │ ├── message_loc: (84,0)-(84,3) = "foo" - │ │ ├── opening_loc: ∅ - │ │ ├── arguments: ∅ - │ │ ├── closing_loc: ∅ - │ │ └── block: ∅ - │ ├── call_operator_loc: ∅ - │ ├── name: :[]= - │ ├── message_loc: (84,3)-(84,9) = "[&bar]" - │ ├── opening_loc: (84,3)-(84,4) = "[" - │ ├── arguments: - │ │ @ ArgumentsNode (location: (84,12)-(84,13)) - │ │ ├── flags: ∅ - │ │ └── arguments: (length: 1) - │ │ └── @ IntegerNode (location: (84,12)-(84,13)) - │ │ ├── flags: decimal - │ │ └── value: 1 - │ ├── closing_loc: (84,8)-(84,9) = "]" - │ └── block: - │ @ BlockArgumentNode (location: (84,4)-(84,8)) - │ ├── expression: - │ │ @ CallNode (location: (84,5)-(84,8)) - │ │ ├── flags: variable_call, ignore_visibility - │ │ ├── receiver: ∅ - │ │ ├── call_operator_loc: ∅ - │ │ ├── name: :bar - │ │ ├── message_loc: (84,5)-(84,8) = "bar" - │ │ ├── opening_loc: ∅ - │ │ ├── arguments: ∅ - │ │ ├── closing_loc: ∅ - │ │ └── block: ∅ - │ └── operator_loc: (84,4)-(84,5) = "&" - ├── @ CallNode (location: (86,0)-(86,17)) - │ ├── flags: attribute_write - │ ├── receiver: - │ │ @ CallNode (location: (86,0)-(86,7)) - │ │ ├── flags: ∅ - │ │ ├── receiver: - │ │ │ @ CallNode (location: (86,0)-(86,3)) - │ │ │ ├── flags: variable_call, ignore_visibility - │ │ │ ├── receiver: ∅ - │ │ │ ├── call_operator_loc: ∅ - │ │ │ ├── name: :foo - │ │ │ ├── message_loc: (86,0)-(86,3) = "foo" - │ │ │ ├── opening_loc: ∅ - │ │ │ ├── arguments: ∅ - │ │ │ ├── closing_loc: ∅ - │ │ │ └── block: ∅ - │ │ ├── call_operator_loc: (86,3)-(86,4) = "." - │ │ ├── name: :foo - │ │ ├── message_loc: (86,4)-(86,7) = "foo" - │ │ ├── opening_loc: ∅ - │ │ ├── arguments: ∅ - │ │ ├── closing_loc: ∅ - │ │ └── block: ∅ - │ ├── call_operator_loc: ∅ - │ ├── name: :[]= - │ ├── message_loc: (86,7)-(86,13) = "[&bar]" - │ ├── opening_loc: (86,7)-(86,8) = "[" - │ ├── arguments: - │ │ @ ArgumentsNode (location: (86,16)-(86,17)) - │ │ ├── flags: ∅ - │ │ └── arguments: (length: 1) - │ │ └── @ IntegerNode (location: (86,16)-(86,17)) - │ │ ├── flags: decimal - │ │ └── value: 1 - │ ├── closing_loc: (86,12)-(86,13) = "]" - │ └── block: - │ @ BlockArgumentNode (location: (86,8)-(86,12)) - │ ├── expression: - │ │ @ CallNode (location: (86,9)-(86,12)) - │ │ ├── flags: variable_call, ignore_visibility - │ │ ├── receiver: ∅ - │ │ ├── call_operator_loc: ∅ - │ │ ├── name: :bar - │ │ ├── message_loc: (86,9)-(86,12) = "bar" - │ │ ├── opening_loc: ∅ - │ │ ├── arguments: ∅ - │ │ ├── closing_loc: ∅ - │ │ └── block: ∅ - │ └── operator_loc: (86,8)-(86,9) = "&" - ├── @ DefNode (location: (88,0)-(90,3)) - │ ├── name: :foo - │ ├── name_loc: (88,4)-(88,7) = "foo" - │ ├── receiver: ∅ - │ ├── parameters: - │ │ @ ParametersNode (location: (88,8)-(88,9)) - │ │ ├── requireds: (length: 0) - │ │ ├── optionals: (length: 0) - │ │ ├── rest: ∅ - │ │ ├── posts: (length: 0) - │ │ ├── keywords: (length: 0) - │ │ ├── keyword_rest: ∅ - │ │ └── block: - │ │ @ BlockParameterNode (location: (88,8)-(88,9)) - │ │ ├── flags: ∅ - │ │ ├── name: ∅ - │ │ ├── name_loc: ∅ - │ │ └── operator_loc: (88,8)-(88,9) = "&" - │ ├── body: - │ │ @ StatementsNode (location: (89,2)-(89,12)) - │ │ └── body: (length: 1) - │ │ └── @ CallNode (location: (89,2)-(89,12)) - │ │ ├── flags: attribute_write - │ │ ├── receiver: - │ │ │ @ CallNode (location: (89,2)-(89,5)) - │ │ │ ├── flags: variable_call, ignore_visibility - │ │ │ ├── receiver: ∅ - │ │ │ ├── call_operator_loc: ∅ - │ │ │ ├── name: :bar - │ │ │ ├── message_loc: (89,2)-(89,5) = "bar" - │ │ │ ├── opening_loc: ∅ - │ │ │ ├── arguments: ∅ - │ │ │ ├── closing_loc: ∅ - │ │ │ └── block: ∅ - │ │ ├── call_operator_loc: ∅ - │ │ ├── name: :[]= - │ │ ├── message_loc: (89,5)-(89,8) = "[&]" - │ │ ├── opening_loc: (89,5)-(89,6) = "[" - │ │ ├── arguments: - │ │ │ @ ArgumentsNode (location: (89,11)-(89,12)) - │ │ │ ├── flags: ∅ - │ │ │ └── arguments: (length: 1) - │ │ │ └── @ IntegerNode (location: (89,11)-(89,12)) - │ │ │ ├── flags: decimal - │ │ │ └── value: 1 - │ │ ├── closing_loc: (89,7)-(89,8) = "]" - │ │ └── block: - │ │ @ BlockArgumentNode (location: (89,6)-(89,7)) - │ │ ├── expression: ∅ - │ │ └── operator_loc: (89,6)-(89,7) = "&" - │ ├── locals: [] - │ ├── def_keyword_loc: (88,0)-(88,3) = "def" - │ ├── operator_loc: ∅ - │ ├── lparen_loc: (88,7)-(88,8) = "(" - │ ├── rparen_loc: (88,9)-(88,10) = ")" - │ ├── equal_loc: ∅ - │ └── end_keyword_loc: (90,0)-(90,3) = "end" ├── @ IndexOperatorWriteNode (location: (92,0)-(92,10)) │ ├── flags: ∅ │ ├── receiver: diff --git a/test/ruby/test_compile_prism.rb b/test/ruby/test_compile_prism.rb index 3dbc63482836e6..65f1d96f97ac8c 100644 --- a/test/ruby/test_compile_prism.rb +++ b/test/ruby/test_compile_prism.rb @@ -2012,24 +2012,6 @@ def obj.[]=(a, b); 10; end obj[*[1]] = 3 RUBY - # Test passing block inside of []= - assert_prism_eval(<<~RUBY) - obj = Object.new - def obj.[]=(a); end - - p = proc {} - obj[&p] = 4 - RUBY - - # Test splat and block inside of []= - assert_prism_eval(<<~RUBY) - obj = Object.new - def obj.[]=(a, b); end - - p = proc {} - obj[*[1], &p] = 4 - RUBY - assert_prism_eval(<<-CODE) def self.prism_opt_var_trail_hash(a = nil, *b, c, **d); end prism_opt_var_trail_hash("a") diff --git a/test/ruby/test_parse.rb b/test/ruby/test_parse.rb index a8abccb1f937b3..051fac274f60e3 100644 --- a/test/ruby/test_parse.rb +++ b/test/ruby/test_parse.rb @@ -916,20 +916,6 @@ def test_set_backref assert_syntax_error("$& = 1", /Can't set variable/) end - def test_arg_concat - o = Object.new - class << o; self; end.instance_eval do - define_method(:[]=) {|*r, &b| b.call(r) } - end - r = nil - assert_nothing_raised do - eval <<-END, nil, __FILE__, __LINE__+1 - o[&proc{|x| r = x }] = 1 - END - end - assert_equal([1], r) - end - def test_void_expr_stmts_value x = 1 useless_use = /useless use/