Fixes to !! operator + tests.

This commit is contained in:
Christoffer Lerno
2020-07-29 11:50:42 +02:00
committed by Christoffer Lerno
parent 7853cb09ac
commit d0ed16e60e
3 changed files with 45 additions and 1 deletions

View File

@@ -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)

View 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

View 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 '!!'
}