From cecadce86d8070ee31d193736d331926efec0fff Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 11 Aug 2022 14:42:29 +0100 Subject: Allow for chaining of '#load(path) or_else #load(path)' --- src/check_expr.cpp | 55 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 26 deletions(-) (limited to 'src/check_expr.cpp') diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 076eaba73..310874139 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -7436,36 +7436,39 @@ ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node, Type *type if (is_load_directive_call(arg)) { LoadDirectiveResult res = check_load_directive(c, &x, arg, type_hint, false); - bool y_is_diverging = false; - check_expr_base(c, &y, default_value, x.type); - switch (y.mode) { - case Addressing_NoValue: - if (is_diverging_expr(y.expr)) { - // Allow - y.mode = Addressing_Value; - y_is_diverging = true; - } else { - error_operand_no_value(&y); + // Allow for chaining of '#load(path) or_else #load(path)' + if (!(is_load_directive_call(default_value) && res == LoadDirective_Success)) { + bool y_is_diverging = false; + check_expr_base(c, &y, default_value, x.type); + switch (y.mode) { + case Addressing_NoValue: + if (is_diverging_expr(y.expr)) { + // Allow + y.mode = Addressing_Value; + y_is_diverging = true; + } else { + error_operand_no_value(&y); + y.mode = Addressing_Invalid; + } + break; + case Addressing_Type: + error_operand_not_expression(&y); y.mode = Addressing_Invalid; + break; } - break; - case Addressing_Type: - error_operand_not_expression(&y); - y.mode = Addressing_Invalid; - break; - } - if (y.mode == Addressing_Invalid) { - o->mode = Addressing_Value; - o->type = t_invalid; - o->expr = node; - return Expr_Expr; - } + if (y.mode == Addressing_Invalid) { + o->mode = Addressing_Value; + o->type = t_invalid; + o->expr = node; + return Expr_Expr; + } - if (!y_is_diverging) { - check_assignment(c, &y, x.type, name); - if (y.mode != Addressing_Constant) { - error(y.expr, "expected a constant expression on the right-hand side of 'or_else' in conjuction with '#load'"); + if (!y_is_diverging) { + check_assignment(c, &y, x.type, name); + if (y.mode != Addressing_Constant) { + error(y.expr, "expected a constant expression on the right-hand side of 'or_else' in conjuction with '#load'"); + } } } -- cgit v1.2.3