Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/prism.c
Original file line number Diff line number Diff line change
Expand Up @@ -13745,6 +13745,9 @@ parse_write(pm_parser_t *parser, pm_node_t *target, pm_token_t *operator, pm_nod

// Replace the name with "[]=".
call->name = pm_parser_constant_id_constant(parser, "[]=", 3);

// Ensure that the arguments for []= don't contain keywords
pm_index_arguments_check(parser, call->arguments, call->block);
pm_node_flag_set((pm_node_t *) call, PM_CALL_NODE_FLAGS_ATTRIBUTE_WRITE | pm_implicit_array_write_flags(value, PM_CALL_NODE_FLAGS_IMPLICIT_ARRAY));

return target;
Expand Down
3 changes: 3 additions & 0 deletions test/prism/errors/block_args_in_array_assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
matrix[5, &block] = 8
^~~~~~ unexpected block arg given in index assignment; blocks are not allowed in index assignment expressions

3 changes: 3 additions & 0 deletions test/prism/errors/keyword_args_in_array_assignment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
matrix[5, axis: :y] = 8
^~~~~~~~ unexpected keyword arg given in index assignment; keywords are not allowed in index assignment expressions

6 changes: 5 additions & 1 deletion test/prism/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class ErrorsTest < TestCase
end

if RUBY_VERSION < "3.4"
filepaths -= ["it_with_ordinary_parameter.txt"]
filepaths -= [
"it_with_ordinary_parameter.txt",
"block_args_in_array_assignment.txt",
"keyword_args_in_array_assignment.txt"
]
end

if RUBY_VERSION < "3.4" || RUBY_RELEASE_DATE < "2024-07-24"
Expand Down
Loading