mirror of
https://github.com/ruby/ruby.git
synced 2025-08-24 13:34:17 +02:00
[ruby/prism] Check void expressions for constant paths
Fix https://github.com/ruby/prism/pull/1920
ee8e03bac7
This commit is contained in:
parent
8654859dbd
commit
3af56e87ca
2 changed files with 16 additions and 0 deletions
|
@ -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 *
|
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_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);
|
pm_constant_path_node_t *node = PM_ALLOC_NODE(parser, pm_constant_path_node_t);
|
||||||
|
|
||||||
*node = (pm_constant_path_node_t) {
|
*node = (pm_constant_path_node_t) {
|
||||||
|
|
|
@ -1654,6 +1654,7 @@ module Prism
|
||||||
(return).(1)
|
(return).(1)
|
||||||
(return)[1]
|
(return)[1]
|
||||||
(return)[1] = 2
|
(return)[1] = 2
|
||||||
|
(return)::foo
|
||||||
RUBY
|
RUBY
|
||||||
message = 'Unexpected void value expression'
|
message = 'Unexpected void value expression'
|
||||||
assert_errors expression(source), source, [
|
assert_errors expression(source), source, [
|
||||||
|
@ -1661,6 +1662,19 @@ module Prism
|
||||||
[message, 14..20],
|
[message, 14..20],
|
||||||
[message, 27..33],
|
[message, 27..33],
|
||||||
[message, 39..45],
|
[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'.
|
], compare_ripper: false # Ripper does not check 'void value expression'.
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue