diff options
| author | gingerBill <bill@gingerbill.org> | 2022-08-11 14:42:29 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-08-11 14:42:29 +0100 |
| commit | cecadce86d8070ee31d193736d331926efec0fff (patch) | |
| tree | 185b0bb187ef96bbb5e96defe68ac6994a8393b2 /src/check_expr.cpp | |
| parent | a7c39060038f63b1840f6eb5c0750bdb47e7d3ea (diff) | |
Allow for chaining of '#load(path) or_else #load(path)'
Diffstat (limited to 'src/check_expr.cpp')
| -rw-r--r-- | src/check_expr.cpp | 55 |
1 files changed, 29 insertions, 26 deletions
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'"); + } } } |