@@ -97,6 +97,19 @@ impl<'c> Translation<'c> {
9797 // Ops like division and bitxor accept inputs of their expected result type.
9898 lhs_type_id. ctype = expr_type_id. ctype ;
9999 rhs_type_id. ctype = expr_type_id. ctype ;
100+
101+ // For complex arithmetic, complex and real values can be mixed.
102+ let expr_type_kind =
103+ & self . ast_context . resolve_type ( expr_type_id. ctype ) . kind ;
104+ if let & CTypeKind :: Complex ( result_scalar_type_id) = expr_type_kind {
105+ if !matches ! ( lhs_type_kind, CTypeKind :: Complex ( ..) ) {
106+ lhs_type_id. ctype = result_scalar_type_id;
107+ }
108+
109+ if !matches ! ( rhs_type_kind, CTypeKind :: Complex ( ..) ) {
110+ rhs_type_id. ctype = result_scalar_type_id;
111+ }
112+ }
100113 } else if op. input_types_same ( ) && lhs_type_kind != rhs_type_kind {
101114 // Ops like comparisons require argument types to match, but the result type
102115 // doesn't inform us what type to choose. Select a synthetic definition of a
@@ -288,7 +301,14 @@ impl<'c> Translation<'c> {
288301 {
289302 // If the rhs must match the lhs but doesn't, add a cast.
290303 // For compound assignment, use the compute type; for regular assignment, use lhs type.
291- let target_type_id = compute_lhs_type_id. unwrap_or ( lhs_type_id) ;
304+ let mut target_type_id = compute_lhs_type_id. unwrap_or ( lhs_type_id) ;
305+
306+ // For complex arithmetic, complex and real values can be mixed.
307+ if let & CTypeKind :: Complex ( lhs_scalar_type_id) = lhs_type_kind {
308+ if !matches ! ( rhs_type_kind, CTypeKind :: Complex ( ..) ) {
309+ target_type_id. ctype = lhs_scalar_type_id;
310+ }
311+ }
292312
293313 rhs_rs = self . convert_cast (
294314 ctx. used ( ) ,
0 commit comments