&&& was accidentally available as a valid prefix operator.

This commit is contained in:
Christoffer Lerno
2025-05-21 23:36:33 +02:00
parent 3cd2267b0a
commit bd1de1e7dc
3 changed files with 17 additions and 0 deletions

View File

@@ -35,6 +35,7 @@
- Error when using named argument on trailing macro body expansion #2139.
- Designated const initializers with `{}` would overwrite the parent field.
- Empty default case in @jump switch does not fallthrough #2147.
- `&&&` was accidentally available as a valid prefix operator.
### Stdlib changes
- Added `String.quick_ztr` and `String.is_zstr`

View File

@@ -703,7 +703,13 @@ static Expr *parse_unary_expr(ParseContext *c, Expr *left)
bool is_bangbang = tok_is(c, TOKEN_BANGBANG);
Expr *unary = EXPR_NEW_TOKEN(EXPR_UNARY);
if (c->tok == TOKEN_CT_AND)
{
PRINT_ERROR_HERE("'&&&' is the compile time '&&' operator. If you want to take a temp address of an address, use () or space to clarify the intent, e.g. '&&(&a)'.");
return poisoned_expr;
}
unary->unary_expr.operator = unaryop_from_token(c->tok);
ASSERT(unary->unary_expr.operator != UNARYOP_ERROR);
advance(c);
Expr *right_side = parse_precedence(c, PREC_UNARY);

View File

@@ -0,0 +1,10 @@
import std;
fn int main()
{
// This works
int** my_super_cool_pointer = &&(&&1);
// This doesn't
int** my_super_cool_pointer2 = &&&&1; // #error: '&&&' is the compile time '&&' operator
return 0;
}