[ruby/prism] Check void expressions for constant paths

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

https://github.com/ruby/prism/commit/ee8e03bac7
This commit is contained in:
TSUYUSATO Kitsune 2023-11-26 16:47:41 +09:00 committed by git
parent 8654859dbd
commit 3af56e87ca
2 changed files with 16 additions and 0 deletions

View File

@ -2457,6 +2457,8 @@ pm_constant_path_or_write_node_create(pm_parser_t *parser, pm_constant_path_node
*/
static pm_constant_path_node_t *
pm_constant_path_node_create(pm_parser_t *parser, pm_node_t *parent, const pm_token_t *delimiter, pm_node_t *child) {
pm_assert_value_expression(parser, parent);
pm_constant_path_node_t *node = PM_ALLOC_NODE(parser, pm_constant_path_node_t);
*node = (pm_constant_path_node_t) {

View File

@ -1654,6 +1654,7 @@ module Prism
(return).(1)
(return)[1]
(return)[1] = 2
(return)::foo
RUBY
message = 'Unexpected void value expression'
assert_errors expression(source), source, [
@ -1661,6 +1662,19 @@ module Prism
[message, 14..20],
[message, 27..33],
[message, 39..45],
[message, 55..61],
], compare_ripper: false # Ripper does not check 'void value expression'.
end
def test_void_value_expression_in_constant_path
source = <<~RUBY
(return)::A
class (return)::A; end
RUBY
message = 'Unexpected void value expression'
assert_errors expression(source), source, [
[message, 1..7],
[message, 19..25],
], compare_ripper: false # Ripper does not check 'void value expression'.
end