Skip to content

Commit 7e133b9

Browse files
committed
Reject assigning command call without parentheses
Fixes: #3106
1 parent 93c0474 commit 7e133b9

9 files changed

+57
-0
lines changed

src/prism.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20884,6 +20884,23 @@ parse_regular_expression_named_captures(pm_parser_t *parser, const pm_string_t *
2088420884
}
2088520885
}
2088620886

20887+
static void
20888+
validate_local_variable_assignment_with_call(pm_parser_t *parser, pm_node_t *node) {
20889+
if (PM_NODE_TYPE_P(node, PM_LOCAL_VARIABLE_WRITE_NODE)) {
20890+
pm_local_variable_write_node_t* cast = (pm_local_variable_write_node_t *)node;
20891+
if (PM_NODE_TYPE_P(cast->value, PM_CALL_NODE)) {
20892+
pm_call_node_t *call_node = (pm_call_node_t *)cast->value;
20893+
if (call_node->arguments != NULL) {
20894+
if (call_node->opening_loc.start == NULL) {
20895+
pm_node_t *arguments = (pm_node_t *)call_node->arguments;
20896+
PM_PARSER_ERR_NODE_FORMAT_CONTENT(parser, arguments, PM_ERR_LAMBDA_OPEN);
20897+
PM_PARSER_ERR_NODE_FORMAT_CONTENT(parser, arguments, PM_ERR_EXPECT_LPAREN_REQ_PARAMETER);
20898+
}
20899+
}
20900+
}
20901+
}
20902+
}
20903+
2088720904
static inline pm_node_t *
2088820905
parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t previous_binding_power, pm_binding_power_t binding_power, bool accepts_command_call, uint16_t depth) {
2088920906
pm_token_t token = parser->current;
@@ -21306,13 +21323,17 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2130621323
parser_lex(parser);
2130721324

2130821325
pm_node_t *right = parse_expression(parser, binding_power, parser->previous.type == PM_TOKEN_KEYWORD_AND, false, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1));
21326+
validate_local_variable_assignment_with_call(parser, node);
21327+
validate_local_variable_assignment_with_call(parser, right);
2130921328
return (pm_node_t *) pm_and_node_create(parser, node, &token, right);
2131021329
}
2131121330
case PM_TOKEN_KEYWORD_OR:
2131221331
case PM_TOKEN_PIPE_PIPE: {
2131321332
parser_lex(parser);
2131421333

2131521334
pm_node_t *right = parse_expression(parser, binding_power, parser->previous.type == PM_TOKEN_KEYWORD_OR, false, PM_ERR_EXPECT_EXPRESSION_AFTER_OPERATOR, (uint16_t) (depth + 1));
21335+
validate_local_variable_assignment_with_call(parser, node);
21336+
validate_local_variable_assignment_with_call(parser, right);
2131621337
return (pm_node_t *) pm_or_node_create(parser, node, &token, right);
2131721338
}
2131821339
case PM_TOKEN_EQUAL_TILDE: {
@@ -21478,13 +21499,17 @@ parse_expression_infix(pm_parser_t *parser, pm_node_t *node, pm_binding_power_t
2147821499
parser_lex(parser);
2147921500

2148021501
pm_node_t *predicate = parse_value_expression(parser, binding_power, true, false, PM_ERR_CONDITIONAL_IF_PREDICATE, (uint16_t) (depth + 1));
21502+
validate_local_variable_assignment_with_call(parser, node);
21503+
validate_local_variable_assignment_with_call(parser, predicate);
2148121504
return (pm_node_t *) pm_if_node_modifier_create(parser, node, &keyword, predicate);
2148221505
}
2148321506
case PM_TOKEN_KEYWORD_UNLESS_MODIFIER: {
2148421507
pm_token_t keyword = parser->current;
2148521508
parser_lex(parser);
2148621509

2148721510
pm_node_t *predicate = parse_value_expression(parser, binding_power, true, false, PM_ERR_CONDITIONAL_UNLESS_PREDICATE, (uint16_t) (depth + 1));
21511+
validate_local_variable_assignment_with_call(parser, node);
21512+
validate_local_variable_assignment_with_call(parser, predicate);
2148821513
return (pm_node_t *) pm_unless_node_modifier_create(parser, node, &keyword, predicate);
2148921514
}
2149021515
case PM_TOKEN_KEYWORD_UNTIL_MODIFIER: {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 and a = p 2
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 if a = p 2
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 or a = p 2
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1 unless a = p 2
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a = p 1 and 2
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a = p 1 if true
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a = p 1 unless true
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
a = p 1 or 2
2+
^ expected a `do` keyword or a `{` to open the lambda block
3+
^ expected a `(` to start a required parameter
4+

0 commit comments

Comments
 (0)