Fixes incorrect type resolution of && and || with optionals. Fixes #879

This commit is contained in:
Christoffer Lerno
2023-07-25 15:16:42 +02:00
parent 3e78a70552
commit d0c00b859b
3 changed files with 16 additions and 2 deletions

View File

@@ -5343,6 +5343,7 @@ static bool sema_expr_analyse_and_or(SemaContext *context, Expr *expr, Expr *lef
if (!sema_binary_analyse_subexpr(context, expr, left, right)) return false; if (!sema_binary_analyse_subexpr(context, expr, left, right)) return false;
if (!cast_explicit(context, left, type_bool) || !cast_explicit(context, right, type_bool)) return false; if (!cast_explicit(context, left, type_bool) || !cast_explicit(context, right, type_bool)) return false;
if (expr_both_const(left, right) && sema_constant_fold_ops(left)) if (expr_both_const(left, right) && sema_constant_fold_ops(left))
{ {
if (expr->binary_expr.operator == BINARYOP_AND) if (expr->binary_expr.operator == BINARYOP_AND)
@@ -5356,7 +5357,7 @@ static bool sema_expr_analyse_and_or(SemaContext *context, Expr *expr, Expr *lef
expr->const_expr.b |= right->const_expr.b; expr->const_expr.b |= right->const_expr.b;
} }
} }
expr->type = type_bool; expr->type = type_add_optional(type_bool, IS_OPTIONAL(left) || IS_OPTIONAL(right));
return true; return true;
} }

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.579" #define COMPILER_VERSION "0.4.580"

View File

@@ -0,0 +1,13 @@
module testing;
import std::io;
fn void! main()
{
bool ok;
if (ok && !foo()) io::printfn("nok"); // #error: The expression may not be an optional
}
fn bool! foo()
{
return false;
}