@@ -1222,19 +1222,24 @@ def mkIfExpr(site, cond, texpr, fexpr):
1222
1222
(texpr , fexpr , utype ) = usual_int_conv (
1223
1223
texpr , ttype , fexpr , ftype )
1224
1224
else :
1225
- if not compatible_types_fuzzy (ttype , ftype ):
1226
- raise EBINOP (site , ':' , texpr , fexpr )
1227
- # TODO: in C, the rules are more complex,
1228
- # but our type system is too primitive to cover that
1229
1225
if (isinstance (ttype , (TPtr , TArray ))
1230
- and isinstance (ftype , (TPtr , TArray ))):
1226
+ and isinstance (ftype , (TPtr , TArray ))
1227
+ and (ttype .base .void or ftype .base .void
1228
+ or compatible_types (safe_realtype_unconst (ttype .base ),
1229
+ safe_realtype_unconst (ftype .base )))):
1231
1230
# if any branch is void, then the union is too
1232
1231
base = (ftype if ftype .base .void else ttype ).base .clone ()
1233
1232
# if any branch is const *, then the union is too
1234
- base .const = ttype .base .const or ftype .base .const
1233
+ base .const = ((isinstance (ttype , TArray ) and ttype .const )
1234
+ or (isinstance (ftype , TArray ) and ftype .const )
1235
+ or shallow_const (ttype .base )
1236
+ or shallow_const (ftype .base ))
1235
1237
utype = TPtr (base )
1236
- else :
1238
+ elif compatible_types (safe_realtype_unconst (ttype ),
1239
+ safe_realtype_unconst (ftype )):
1237
1240
utype = ttype
1241
+ else :
1242
+ raise EBINOP (site , ':' , texpr , fexpr )
1238
1243
if cond .constant :
1239
1244
# should be safe: texpr and fexpr now have compatible types
1240
1245
return texpr if cond .value else fexpr
@@ -1396,7 +1401,8 @@ def make(cls, site, lh, rh):
1396
1401
if ((lhtype .is_arith and rhtype .is_arith )
1397
1402
or (isinstance (lhtype , (TPtr , TArray ))
1398
1403
and isinstance (rhtype , (TPtr , TArray ))
1399
- and compatible_types_fuzzy (lhtype .base , rhtype .base ))):
1404
+ and compatible_types (safe_realtype_unconst (lhtype .base ),
1405
+ safe_realtype_unconst (rhtype .base )))):
1400
1406
return cls .make_simple (site , lh , rh )
1401
1407
raise EILLCOMP (site , lh , lhtype , rh , rhtype )
1402
1408
@@ -1601,7 +1607,9 @@ def make(cls, site, lh, rh):
1601
1607
if ((lhtype .is_arith and rhtype .is_arith )
1602
1608
or (isinstance (lhtype , (TPtr , TArray ))
1603
1609
and isinstance (rhtype , (TPtr , TArray ))
1604
- and compatible_types_fuzzy (lhtype , rhtype ))
1610
+ and (compatible_types (safe_realtype_unconst (lhtype .base ),
1611
+ safe_realtype_unconst (rhtype .base ))
1612
+ or lhtype .base .void or rhtype .base .void ))
1605
1613
or (isinstance (lhtype , TBool ) and isinstance (rhtype , TBool ))):
1606
1614
return Equals (site , lh , rh )
1607
1615
0 commit comments