aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2025-03-27 15:08:53 +0000
committergingerBill <bill@gingerbill.org>2025-03-27 15:08:53 +0000
commitd3f0b31fcc48772f1457fa1eb487fd7afcc6d43d (patch)
tree4db4041d35930e4a1f844b2b2919985bf8665bbf
parent71db9ac1ba7ca3aef94bfd026b0e4bc444a20124 (diff)
Improve `or_else` type inference logic
-rw-r--r--src/check_expr.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/check_expr.cpp b/src/check_expr.cpp
index 6fba64765..91d9e669f 100644
--- a/src/check_expr.cpp
+++ b/src/check_expr.cpp
@@ -8977,8 +8977,14 @@ gb_internal ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node
o->expr = node;
return Expr_Expr;
}
+
+ Type *left_type = nullptr;
+ Type *right_type = nullptr;
+ check_or_else_split_types(c, &x, name, &left_type, &right_type);
+ add_type_and_value(c, arg, x.mode, x.type, x.value);
+
bool y_is_diverging = false;
- check_expr_base(c, &y, default_value, x.type);
+ check_expr_base(c, &y, default_value, left_type);
switch (y.mode) {
case Addressing_NoValue:
if (is_diverging_expr(y.expr)) {
@@ -9003,11 +9009,6 @@ gb_internal ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node
return Expr_Expr;
}
- Type *left_type = nullptr;
- Type *right_type = nullptr;
- check_or_else_split_types(c, &x, name, &left_type, &right_type);
- add_type_and_value(c, arg, x.mode, x.type, x.value);
-
if (left_type != nullptr) {
if (!y_is_diverging) {
check_assignment(c, &y, left_type, name);