From f2d27229d23b3e7044d1798b022902cc14848084 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 4 Aug 2025 12:25:09 +0200 Subject: [PATCH] Bug causing a compiler error when parsing a broken lambda inside of an expression. --- releasenotes.md | 1 + src/compiler/parse_expr.c | 2 +- src/compiler/parse_stmt.c | 4 ++-- test/test_suite/lambda/lambda_broken_in_expr.c3 | 5 +++++ 4 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 test/test_suite/lambda/lambda_broken_in_expr.c3 diff --git a/releasenotes.md b/releasenotes.md index 7f4d0ac3a..0b6c0d0b3 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -12,6 +12,7 @@ - Codegen error in `if (try x = (true ? io::EOF? : 1))`, i.e. using if-try with a known Empty. - Codegen error in `if (try x = (false ? io::EOF? : 1))`, i.e. using if-try with a CT known value. - Reduce allocated Vmem for the compiler on 32 bit machines. +- Bug causing a compiler error when parsing a broken lambda inside of an expression. ### Stdlib changes - Add `==` to `Pair`, `Triple` and TzDateTime. Add print to `Pair` and `Triple`. diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index f6d8cd74c..b11ae2244 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -405,7 +405,7 @@ static Expr *parse_lambda(ParseContext *c, Expr *left, SourceSpan lhs_span) Decl **decls = NULL; Variadic variadic = VARIADIC_NONE; int vararg_index = -1; - if (!parse_parameters(c, &decls, &variadic, &vararg_index, PARAM_PARSE_LAMBDA)) return false; + if (!parse_parameters(c, &decls, &variadic, &vararg_index, PARAM_PARSE_LAMBDA)) return poisoned_expr; CONSUME_OR_RET(TOKEN_RPAREN, poisoned_expr); Signature *sig = &func->func_decl.signature; sig->vararg_index = vararg_index < 0 ? vec_size(decls) : vararg_index; diff --git a/src/compiler/parse_stmt.c b/src/compiler/parse_stmt.c index 0b40e3bb4..fbc6728b5 100644 --- a/src/compiler/parse_stmt.c +++ b/src/compiler/parse_stmt.c @@ -428,7 +428,7 @@ static inline Ast* parse_asm_block_stmt(ParseContext *c) else { PRINT_ERROR_HERE("Only the '@pure' attribute is allowed."); - return false; + return poisoned_ast; } advance_and_verify(c, TOKEN_AT_IDENT); if (!tok_is(c, TOKEN_LBRACE)) @@ -463,7 +463,7 @@ static inline Ast* parse_asm_block_stmt(ParseContext *c) else { PRINT_ERROR_HERE("Only the '@pure' attribute is allowed."); - return false; + return poisoned_ast; } advance_and_verify(c, TOKEN_AT_IDENT); } diff --git a/test/test_suite/lambda/lambda_broken_in_expr.c3 b/test/test_suite/lambda/lambda_broken_in_expr.c3 new file mode 100644 index 000000000..21b1c7859 --- /dev/null +++ b/test/test_suite/lambda/lambda_broken_in_expr.c3 @@ -0,0 +1,5 @@ +macro int main2() +{ + (fn void (*arg) { // #error: Expected a parameter + })(&&true); +} \ No newline at end of file