Added chained unwrap test and fixed the same.

This commit is contained in:
Christoffer Lerno
2021-08-03 19:25:00 +02:00
committed by Christoffer Lerno
parent c12cba67a8
commit 991f24d06a
2 changed files with 55 additions and 2 deletions

View File

@@ -1100,7 +1100,7 @@ static inline bool sema_expr_analyse_call_invocation(Context *context, Expr *cal
break;
case VARDECL_PARAM:
// foo
if (!sema_analyse_expr_of_required_type(context, param->type, arg, false)) return false;
if (!sema_analyse_expr_of_required_type(context, param->type, arg, true)) return false;
if (!param->type && !cast_implicitly_to_runtime(arg))
{
SEMA_ERROR(arg, "Constant cannot implicitly be cast to a real type.");
@@ -1117,7 +1117,7 @@ static inline bool sema_expr_analyse_call_invocation(Context *context, Expr *cal
// compile time variables during evaluation:
assert(callee.macro);
SCOPE_START
if (!sema_analyse_expr_of_required_type(context, param->type, arg, false)) return SCOPE_POP_ERROR();
if (!sema_analyse_expr_of_required_type(context, param->type, arg, true)) return SCOPE_POP_ERROR();
SCOPE_END;
break;
case VARDECL_PARAM_CT:

View File

@@ -0,0 +1,53 @@
// #target: x64_darwin
extern func char*! readLine();
extern func int! atoi(char*);
extern func int printf(char* fmt, ...);
func void main()
{
try (int val = atoi(readLine()))
{
printf("You typed the number %d\n", val);
return;
}
printf("You didn't type an integer :(\n");
}
// #expect: try_with_chained_unwrap.ll
entry:
%val = alloca i32, align 4
%retparam = alloca i32, align 4
%retparam1 = alloca i8*, align 8
%result = alloca %error_union, align 8
%result2 = alloca %error_union, align 8
%0 = call { i64, i64 } @readLine(i8** %retparam1)
%1 = bitcast %error_union* %result to { i64, i64 }*
store { i64, i64 } %0, { i64, i64 }* %1, align 8
%err_domain = getelementptr inbounds %error_union, %error_union* %result, i32 0, i32 0
%2 = load i64, i64* %err_domain, align 8
%not_err = icmp eq i64 %2, 0
br i1 %not_err, label %after_check, label %after_try
after_check:
%3 = load i8*, i8** %retparam1, align 8
%4 = call { i64, i64 } @atoi(i32* %retparam, i8* %3)
%5 = bitcast %error_union* %result2 to { i64, i64 }*
store { i64, i64 } %4, { i64, i64 }* %5, align 8
%err_domain3 = getelementptr inbounds %error_union, %error_union* %result2, i32 0, i32 0
%6 = load i64, i64* %err_domain3, align 8
%not_err4 = icmp eq i64 %6, 0
br i1 %not_err4, label %after_check5, label %after_try
after_check5:
%7 = load i32, i32* %retparam, align 4
store i32 %7, i32* %val, align 4
%8 = load i32, i32* %val, align 4
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i32 0, i32 0), i32 %8)
ret void
after_try:
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i32 0, i32 0))
ret void