[ruby/prism] Fix not receiver

`not foo` should be `!foo`
`not()` should be `!nil`

Fixes [Bug #21027]

https://github.com/ruby/prism/commit/871ed4b462
This commit is contained in:
Kevin Newton 2025-01-11 15:38:41 -05:00
parent 9c962ea792
commit 117d6e145a
2 changed files with 16 additions and 5 deletions

View File

@ -1045,10 +1045,20 @@ module Prism
bounds(node.location)
on_unary(node.name, receiver)
when :!
receiver = visit(node.receiver)
if node.message == "not"
receiver =
if !node.receiver.is_a?(ParenthesesNode) || !node.receiver.body.nil?
visit(node.receiver)
end
bounds(node.location)
on_unary(node.message == "not" ? :not : :!, receiver)
bounds(node.location)
on_unary(:not, receiver)
else
receiver = visit(node.receiver)
bounds(node.location)
on_unary(:!, receiver)
end
when *BINARY_OPERATORS
receiver = visit(node.receiver)
value = visit(node.arguments.arguments.first)

View File

@ -19719,11 +19719,12 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
accept1(parser, PM_TOKEN_NEWLINE);
if (accept1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
arguments.opening_loc = PM_LOCATION_TOKEN_VALUE(&parser->previous);
pm_token_t lparen = parser->previous;
if (accept1(parser, PM_TOKEN_PARENTHESIS_RIGHT)) {
arguments.closing_loc = PM_LOCATION_TOKEN_VALUE(&parser->previous);
receiver = (pm_node_t *) pm_parentheses_node_create(parser, &lparen, NULL, &parser->previous);
} else {
arguments.opening_loc = PM_LOCATION_TOKEN_VALUE(&lparen);
receiver = parse_expression(parser, PM_BINDING_POWER_COMPOSITION, true, false, PM_ERR_NOT_EXPRESSION, (uint16_t) (depth + 1));
if (!parser->recovering) {