mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixes to !! operator + tests.
This commit is contained in:
committed by
Christoffer Lerno
parent
7853cb09ac
commit
d0ed16e60e
@@ -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)
|
||||
|
||||
27
test/test_suite/errors/rethrow.c3t
Normal file
27
test/test_suite/errors/rethrow.c3t
Normal file
@@ -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
|
||||
17
test/test_suite/errors/rethrow_no_err.c3
Normal file
17
test/test_suite/errors/rethrow_no_err.c3
Normal file
@@ -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 '!!'
|
||||
}
|
||||
Reference in New Issue
Block a user