[ruby/prism] Check "void value expression" for array literals

Fix https://github.com/ruby/prism/pull/1978

https://github.com/ruby/prism/commit/194c997d0a
This commit is contained in:
TSUYUSATO Kitsune 2023-12-04 13:00:41 +09:00 коммит произвёл git
Родитель 85bc80a51b
Коммит 2a65d83707
2 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -13666,7 +13666,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
pm_parser_err_token(parser, &operator, PM_ERR_ARGUMENT_NO_FORWARDING_STAR);
}
} else {
expression = parse_expression(parser, PM_BINDING_POWER_DEFINED, PM_ERR_ARRAY_EXPRESSION_AFTER_STAR);
expression = parse_value_expression(parser, PM_BINDING_POWER_DEFINED, PM_ERR_ARRAY_EXPRESSION_AFTER_STAR);
}
element = (pm_node_t *) pm_splat_node_create(parser, &operator, expression);
@ -13684,7 +13684,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
parsed_bare_hash = true;
} else {
element = parse_expression(parser, PM_BINDING_POWER_DEFINED, PM_ERR_ARRAY_EXPRESSION);
element = parse_value_expression(parser, PM_BINDING_POWER_DEFINED, PM_ERR_ARRAY_EXPRESSION);
if (pm_symbol_node_label_p(element) || accept1(parser, PM_TOKEN_EQUAL_GREATER)) {
if (parsed_bare_hash) {
@ -13700,7 +13700,7 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power) {
operator = not_provided(parser);
}
pm_node_t *value = parse_expression(parser, PM_BINDING_POWER_DEFINED, PM_ERR_HASH_VALUE);
pm_node_t *value = parse_value_expression(parser, PM_BINDING_POWER_DEFINED, PM_ERR_HASH_VALUE);
pm_node_t *assoc = (pm_node_t *) pm_assoc_node_create(parser, element, &operator, value);
pm_keyword_hash_node_elements_append(hash, assoc);

Просмотреть файл

@ -1660,6 +1660,28 @@ module Prism
], compare_ripper: false # Ripper does not check 'void value expression'.
end
def test_void_value_expression_in_array
source = <<~RUBY
[return]
[1, return]
[ return => 1 ]
[ 1 => return ]
[ a: return ]
[ *return ]
[ **return ]
RUBY
message = 'unexpected void value expression'
assert_errors expression(source), source, [
[message, 1..7],
[message, 13..19],
[message, 23..29],
[message, 44..50],
[message, 58..64],
[message, 70..76],
[message, 83..89],
], compare_ripper: false # Ripper does not check 'void value expression'.
end
def test_void_value_expression_in_hash
source = <<~RUBY
{ return => 1 }