mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve error message #543
This commit is contained in:
committed by
Christoffer Lerno
parent
c9ae0779e7
commit
5386b6fe50
@@ -8082,6 +8082,15 @@ bool sema_analyse_expr_rhs(SemaContext *context, Type *to, Expr *expr, bool allo
|
||||
assert(allow_failable);
|
||||
}
|
||||
if (!sema_analyse_inferred_expr(context, to, expr)) return false;
|
||||
if (to && allow_failable && to->canonical != expr->type->canonical && expr->type->canonical->type_kind == TYPE_FAULTTYPE)
|
||||
{
|
||||
Type *canonical = type_flatten_distinct(to);
|
||||
if (canonical != type_anyerr && canonical->type_kind != TYPE_FAULTTYPE && expr->expr_kind == EXPR_CONST)
|
||||
{
|
||||
sema_error_at_after(expr->span, "You need to add a trailing '!' here to make this an optional.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (to && !cast_implicit(expr, to)) return false;
|
||||
if (!allow_failable && IS_OPTIONAL(expr))
|
||||
{
|
||||
|
||||
7
test/test_suite/errors/missing_bang.c3
Normal file
7
test/test_suite/errors/missing_bang.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
fault Bob { FOO }
|
||||
|
||||
fn int! test()
|
||||
{
|
||||
return Bob.FOO; // #error: You need to add a trailing
|
||||
}
|
||||
7
test/test_suite2/errors/missing_bang.c3
Normal file
7
test/test_suite2/errors/missing_bang.c3
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
fault Bob { FOO }
|
||||
|
||||
fn int! test()
|
||||
{
|
||||
return Bob.FOO; // #error: You need to add a trailing
|
||||
}
|
||||
Reference in New Issue
Block a user