Skip to content

Commit 0513cf2

Browse files
mamekddnewton
authored andcommitted
Reject true && not true
A command-call-like `not true` must be rejected after `&&` and `||`. https://bugs.ruby-lang.org/issues/21337
1 parent 8070463 commit 0513cf2

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ errors:
101101
- EXPECT_FOR_DELIMITER
102102
- EXPECT_IDENT_REQ_PARAMETER
103103
- EXPECT_IN_DELIMITER
104+
- EXPECT_LPAREN_AFTER_NOT
104105
- EXPECT_LPAREN_REQ_PARAMETER
105106
- EXPECT_MESSAGE
106107
- EXPECT_RBRACKET

src/prism.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19756,6 +19756,11 @@ 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 (!accepts_command_call && !match1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {
19760+
pm_parser_err_current(parser, PM_ERR_EXPECT_LPAREN_AFTER_NOT);
19761+
return (pm_node_t *) pm_missing_node_create(parser, parser->current.start, parser->current.end);
19762+
}
19763+
1975919764
accept1(parser, PM_TOKEN_NEWLINE);
1976019765

1976119766
if (accept1(parser, PM_TOKEN_PARENTHESIS_LEFT)) {

templates/src/diagnostic.c.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ 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] = { "expected a `(` after `not`", PM_ERROR_LEVEL_SYNTAX },
187188
[PM_ERR_EXPECT_LPAREN_REQ_PARAMETER] = { "expected a `(` to start a required parameter", PM_ERROR_LEVEL_SYNTAX },
188189
[PM_ERR_EXPECT_MESSAGE] = { "unexpected %s; expecting a message to send to the receiver", PM_ERROR_LEVEL_SYNTAX },
189190
[PM_ERR_EXPECT_RBRACKET] = { "expected a matching `]`", PM_ERROR_LEVEL_SYNTAX },
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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 `(` after `not`
11+
^ unexpected '(', expecting end-of-input
12+

0 commit comments

Comments
 (0)