mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fixes incorrect type resolution of && and || with optionals. Fixes #879
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
#define COMPILER_VERSION "0.4.579"
|
#define COMPILER_VERSION "0.4.580"
|
||||||
13
test/test_suite/expressions/optional_and_error.c3
Normal file
13
test/test_suite/expressions/optional_and_error.c3
Normal 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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user