Browse Source

Improve `or_else` type inference logic

gingerBill 4 months ago
parent
commit
d3f0b31fcc
1 changed files with 7 additions and 6 deletions
  1. 7 6
      src/check_expr.cpp

+ 7 - 6
src/check_expr.cpp

@@ -8977,8 +8977,14 @@ gb_internal ExprKind check_or_else_expr(CheckerContext *c, Operand *o, Ast *node
 		o->expr = node;
 		o->expr = node;
 		return Expr_Expr;
 		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;
 	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) {
 	switch (y.mode) {
 	case Addressing_NoValue:
 	case Addressing_NoValue:
 		if (is_diverging_expr(y.expr)) {
 		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;
 		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 (left_type != nullptr) {
 		if (!y_is_diverging) {
 		if (!y_is_diverging) {
 			check_assignment(c, &y, left_type, name);
 			check_assignment(c, &y, left_type, name);