gingerBill 3 years ago
parent
commit
9f10487678
1 changed files with 8 additions and 2 deletions
  1. 8 2
      src/check_expr.cpp

+ 8 - 2
src/check_expr.cpp

@@ -2959,7 +2959,14 @@ void check_binary_matrix(CheckerContext *c, Token const &op, Operand *x, Operand
 					goto matrix_error;
 					goto matrix_error;
 				}
 				}
 				x->mode = Addressing_Value;
 				x->mode = Addressing_Value;
-				x->type = alloc_type_matrix(xt->Matrix.elem, xt->Matrix.row_count, yt->Matrix.column_count);
+				if (are_types_identical(xt, yt)) {
+					if (!is_type_named(x->type) && is_type_named(y->type)) {
+						// prefer the named type
+						x->type = y->type;
+					}
+				} else {
+					x->type = alloc_type_matrix(xt->Matrix.elem, xt->Matrix.row_count, yt->Matrix.column_count);
+				}
 				goto matrix_success;
 				goto matrix_success;
 			} else if (yt->kind == Type_Array) {
 			} else if (yt->kind == Type_Array) {
 				if (!are_types_identical(xt->Matrix.elem, yt->Array.elem)) {
 				if (!are_types_identical(xt->Matrix.elem, yt->Array.elem)) {
@@ -3021,7 +3028,6 @@ void check_binary_matrix(CheckerContext *c, Token const &op, Operand *x, Operand
 
 
 matrix_success:
 matrix_success:
 	x->type = check_matrix_type_hint(x->type, type_hint);
 	x->type = check_matrix_type_hint(x->type, type_hint);
-	
 	return;
 	return;