Skip to content

Commit a309213

Browse files
authored
Merge pull request #3585 from mame/no-command-call-not-after-ampersand-ampersand
Reject `true && not true`
2 parents 8070463 + d9151b8 commit a309213

4 files changed

Lines changed: 35 additions & 0 deletions

File tree

config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ errors:
101101
- EXPECT_FOR_DELIMITER
102102
- EXPECT_IDENT_REQ_PARAMETER
103103
- EXPECT_IN_DELIMITER
104+
- EXPECT_LPAREN_AFTER_NOT_LPAREN
105+
- EXPECT_LPAREN_AFTER_NOT_OTHER
104106
- EXPECT_LPAREN_REQ_PARAMETER
105107
- EXPECT_MESSAGE
106108
- EXPECT_RBRACKET

src/prism.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19756,6 +19756,20 @@ parse_expression_prefix(pm_parser_t *parser, pm_binding_power_t binding_power, b
1975619756
pm_arguments_t arguments = { 0 };
1975719757
pm_node_t *receiver = NULL;
1975819758

19759+
// If we do not accept a command call, then we also do not accept a
19760+
// not without parentheses. In this case we need to reject this
19761+
// syntax.
19762+
if (!accepts_command_call && !match1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
19763+
if (match1(parser, PM_TOKEN_PARENTHESIS_LEFT_PARENTHESES)) {
19764+
pm_parser_err(parser, parser->previous.end, parser->previous.end + 1, PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN);
19765+
} else {
19766+
accept1(parser, PM_TOKEN_NEWLINE);
19767+
pm_parser_err_current(parser, PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER);
19768+
}
19769+
19770+
return (pm_node_t *) pm_missing_node_create(parser, parser->current.start, parser->current.end);
19771+
}
19772+
1975919773
accept1(parser, PM_TOKEN_NEWLINE);
1976019774

1976119775
if (accept1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {

templates/src/diagnostic.c.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ static const pm_diagnostic_data_t diagnostic_messages[PM_DIAGNOSTIC_ID_MAX] = {
184184
[PM_ERR_EXPECT_FOR_DELIMITER] = { "unexpected %s; expected a 'do', newline, or ';' after the 'for' loop collection", PM_ERROR_LEVEL_SYNTAX },
185185
[PM_ERR_EXPECT_IDENT_REQ_PARAMETER] = { "expected an identifier for the required parameter", PM_ERROR_LEVEL_SYNTAX },
186186
[PM_ERR_EXPECT_IN_DELIMITER] = { "expected a delimiter after the patterns of an `in` clause", PM_ERROR_LEVEL_SYNTAX },
187+
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_LPAREN] = { "expected a `(` immediately after `not`", PM_ERROR_LEVEL_SYNTAX },
188+
[PM_ERR_EXPECT_LPAREN_AFTER_NOT_OTHER] = { "expected a `(` after `not`", PM_ERROR_LEVEL_SYNTAX },
187189
[PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX },
188190
[PM_ERR_EXPECT_MESSAGE] = { "unexpected %s; expecting a message to send to the receiver", PM_ERROR_LEVEL_SYNTAX },
189191
[PM_ERR_EXPECT_RBRACKET] = { "expected a matching `]`", PM_ERROR_LEVEL_SYNTAX },
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
true && not true
2+
^~~~ expected a `(` after `not`
3+
^~~~ unexpected 'true', expecting end-of-input
4+
5+
true || not true
6+
^~~~ expected a `(` after `not`
7+
^~~~ unexpected 'true', expecting end-of-input
8+
9+
true && not (true)
10+
^ expected a `(` immediately after `not`
11+
^ unexpected '(', expecting end-of-input
12+
13+
true && not
14+
true
15+
^~~~ expected a `(` after `not`
16+
^~~~ unexpected 'true', expecting end-of-input
17+

0 commit comments

Comments
 (0)