Fix lack of location for reporting lambdas with missing return statement #1857.

This commit is contained in:
Christoffer Lerno
2025-01-17 11:55:56 +01:00
parent d4bd68c188
commit d72ec09cee
4 changed files with 14 additions and 4 deletions

View File

@@ -8,6 +8,7 @@
### Fixes
- Fix issue requiring prefix on a generic interface declaration.
- Fix bug in SHA1 for longer blocks #1854.
- Fix lack of location for reporting lambdas with missing return statement #1857.
### Stdlib changes
- Added '%h' and '%H' for printing out binary data in hexadecimal using the formatter.

View File

@@ -408,6 +408,7 @@ static Expr *parse_lambda(ParseContext *c, Expr *left)
Expr *expr = EXPR_NEW_TOKEN(EXPR_LAMBDA);
advance_and_verify(c, TOKEN_FN);
Decl *func = decl_calloc();
func->span = c->prev_span;
func->decl_kind = DECL_FUNC;
func->visibility = VISIBLE_LOCAL;
func->func_decl.generated_lambda = NULL;
@@ -429,7 +430,7 @@ static Expr *parse_lambda(ParseContext *c, Expr *left)
sig->rtype = return_type ? type_infoid(return_type) : 0;
sig->variadic = variadic;
if (!parse_attributes(c, &func->attributes, NULL, NULL, NULL)) return poisoned_expr;
RANGE_EXTEND_PREV(func);
if (tok_is(c, TOKEN_IMPLIES))
{
ASSIGN_ASTID_OR_RET(func->func_decl.body,

View File

@@ -3315,11 +3315,10 @@ bool sema_analyse_function_body(SemaContext *context, Decl *func)
if (!is_naked) sema_append_contract_asserts(assert_first, body);
Type *canonical_rtype = type_no_optional(prototype->rtype)->canonical;
if (!sema_analyse_compound_statement_no_scope(context, body)) return false;
ASSERT0(context->active_scope.depth == 1);
ASSERT(func,context->active_scope.depth == 1);
if (!context->active_scope.jump_end && canonical_rtype != type_void)
{
SEMA_ERROR(func, "Missing return statement at the end of the function.");
return false;
RETURN_SEMA_ERROR(func, "Missing return statement at the end of the function.");
}
SCOPE_END;
if (lambda_params)

View File

@@ -0,0 +1,9 @@
import std::io::path;
fn void! process_dir(String dir_name)
{
path::Path p = path::temp_new(dir_name)!;
path::PathWalker fnwalk = fn bool!(Path p, bool is_dir, void*) { // #error: issing return statement at the end
io::printfn("path is %s", p);
};
}