Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure VCALL flag is turned off when suffixed by a ? or ! #1203

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions src/yarp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,6 @@ yp_call_node_variable_call_create(yp_parser_t *parser, yp_token_t *message) {
node->message_loc = YP_OPTIONAL_LOCATION_TOKEN_VALUE(message);

yp_string_shared_init(&node->name, message->start, message->end);
node->flags |= YP_CALL_NODE_FLAGS_VARIABLE_CALL;

return node;
}

Expand Down Expand Up @@ -9351,18 +9349,21 @@ parse_alias_argument(yp_parser_t *parser, bool first) {
// Parse an identifier into either a local variable read or a call.
static yp_node_t *
parse_variable_call(yp_parser_t *parser) {
int depth;
uint32_t flags = 0;

if (
(parser->current.type != YP_TOKEN_PARENTHESIS_LEFT) &&
(parser->previous.end[-1] != '!') &&
(parser->previous.end[-1] != '?') &&
(depth = yp_parser_local_depth(parser, &parser->previous)) != -1
) {
return (yp_node_t *) yp_local_variable_read_node_create(parser, &parser->previous, (uint32_t) depth);
if (!match_type_p(parser, YP_TOKEN_PARENTHESIS_LEFT) && (parser->previous.end[-1] != '!') && (parser->previous.end[-1] != '?')) {
int depth;
if ((depth = yp_parser_local_depth(parser, &parser->previous)) != -1) {
return (yp_node_t *) yp_local_variable_read_node_create(parser, &parser->previous, (uint32_t) depth);
}

flags |= YP_CALL_NODE_FLAGS_VARIABLE_CALL;
}

return (yp_node_t *) yp_call_node_variable_call_create(parser, &parser->previous);
yp_call_node_t *node = yp_call_node_variable_call_create(parser, &parser->previous);
node->flags = flags;

return (yp_node_t *) node;
}

static inline yp_token_t
Expand Down Expand Up @@ -10485,7 +10486,7 @@ parse_expression_prefix(yp_parser_t *parser, yp_binding_power_t binding_power) {
if (parse_arguments_list(parser, &arguments, true)) {
// Since we found arguments, we need to turn off the
// variable call bit in the flags.
call->flags ^= YP_CALL_NODE_FLAGS_VARIABLE_CALL;
call->flags &= (uint32_t) ~YP_CALL_NODE_FLAGS_VARIABLE_CALL;

call->opening_loc = arguments.opening_loc;
call->arguments = arguments.arguments;
Expand Down
2 changes: 1 addition & 1 deletion test/snapshots/hashes.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/snapshots/method_calls.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions test/snapshots/ternary_operator.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/snapshots/unless.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/snapshots/until.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/snapshots/while.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions test/snapshots/whitequark/kwbegin_compstmt.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/snapshots/whitequark/send_self.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.