mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix lack of location for reporting lambdas with missing return statement #1857.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
|
||||
9
test/test_suite/functions/missing_return_lambda.c3
Normal file
9
test/test_suite/functions/missing_return_lambda.c3
Normal 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);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user