Skip to content

Commit ac69170

Browse files
authored
Merge pull request #3311 from eightbitraptor/mvh-index-assignment
Blocks & kwargs are not valid in index assignments
2 parents cdf702b + e612df5 commit ac69170

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

src/prism.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13745,6 +13745,9 @@ parse_write(pm_parser_t *parser, pm_node_t *target, pm_token_t *operator, pm_nod
1374513745

1374613746
// Replace the name with "[]=".
1374713747
call->name = pm_parser_constant_id_constant(parser, "[]=", 3);
13748+
13749+
// Ensure that the arguments for []= don't contain keywords
13750+
pm_index_arguments_check(parser, call->arguments, call->block);
1374813751
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));
1374913752

1375013753
return target;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
matrix[5, &block] = 8
2+
^~~~~~ unexpected block arg given in index assignment; blocks are not allowed in index assignment expressions
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
matrix[5, axis: :y] = 8
2+
^~~~~~~~ unexpected keyword arg given in index assignment; keywords are not allowed in index assignment expressions
3+

test/prism/errors_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ class ErrorsTest < TestCase
1919
end
2020

2121
if RUBY_VERSION < "3.4"
22-
filepaths -= ["it_with_ordinary_parameter.txt"]
22+
filepaths -= [
23+
"it_with_ordinary_parameter.txt",
24+
"block_args_in_array_assignment.txt",
25+
"keyword_args_in_array_assignment.txt"
26+
]
2327
end
2428

2529
if RUBY_VERSION < "3.4" || RUBY_RELEASE_DATE < "2024-07-24"

0 commit comments

Comments
 (0)