diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 6b970c777..32a587730 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -2937,7 +2937,7 @@ static inline bool sema_expr_analyse_guard(Context *context, Type *to, Expr *exp expr->type = inner->type; if (!inner->failable) { - SEMA_ERROR(inner, "No failable to rethrow before '!!' in the expression, please remove '!!'."); + SEMA_ERROR(expr, "No failable to rethrow before '!!' in the expression, please remove '!!'."); return false; } if (!context->failable_return) diff --git a/test/test_suite/errors/rethrow.c3t b/test/test_suite/errors/rethrow.c3t new file mode 100644 index 000000000..2c59aca51 --- /dev/null +++ b/test/test_suite/errors/rethrow.c3t @@ -0,0 +1,27 @@ + +func void! test() +{ + int! i; + i!!; +} + +// #expect: rethrow.ll + + %i = alloca i32 + %i1 = alloca i128 + %0 = alloca i128 + store i128 0, i128* %i1 + %1 = load i128, i128* %i1 + %2 = icmp eq i128 %1, 0 + br i1 %2, label %after_check, label %error +error: + store i128 %1, i128* %0 + br label %guard_block +after_check: + %3 = load i32, i32* %i + br label %noerr_block +guard_block: + %4 = load i128, i128* %0 + ret i128 %4 +noerr_block: + ret i128 0 diff --git a/test/test_suite/errors/rethrow_no_err.c3 b/test/test_suite/errors/rethrow_no_err.c3 new file mode 100644 index 000000000..a3f5dfe27 --- /dev/null +++ b/test/test_suite/errors/rethrow_no_err.c3 @@ -0,0 +1,17 @@ + +func void test() +{ + test()!!; // #error: No failable to rethrow before '!!' in the expression, please remove '!!' + int i = 0; + if (i!!) return; // #error: No failable to rethrow before '!!' in the expression, please remove '!!' + int! j = 0; + if (j!!) return; // #error: This expression implicitly returns with a failable result, but the function + if ((j!!)!!) return; // #error: This expression implicitly returns with a failable result, but the function +} + +func void! test2() +{ + int! j = 0; + if (j!!) return; + if ((j!!)!!) return; // #error: No failable to rethrow before '!!' in the expression, please remove '!!' +} \ No newline at end of file