Skip to content

Commit 20f5f51

Browse files
committed
Get rid of remaining ungated usages of compatible_types_fuzzy
1 parent 6f9335d commit 20f5f51

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

py/dml/ctree.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,19 +1222,24 @@ def mkIfExpr(site, cond, texpr, fexpr):
12221222
(texpr, fexpr, utype) = usual_int_conv(
12231223
texpr, ttype, fexpr, ftype)
12241224
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
12291225
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)))):
12311230
# if any branch is void, then the union is too
12321231
base = (ftype if ftype.base.void else ttype).base.clone()
12331232
# 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))
12351237
utype = TPtr(base)
1236-
else:
1238+
elif compatible_types(safe_realtype_unconst(ttype),
1239+
safe_realtype_unconst(ftype)):
12371240
utype = ttype
1241+
else:
1242+
raise EBINOP(site, ':', texpr, fexpr)
12381243
if cond.constant:
12391244
# should be safe: texpr and fexpr now have compatible types
12401245
return texpr if cond.value else fexpr
@@ -1396,7 +1401,8 @@ def make(cls, site, lh, rh):
13961401
if ((lhtype.is_arith and rhtype.is_arith)
13971402
or (isinstance(lhtype, (TPtr, TArray))
13981403
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)))):
14001406
return cls.make_simple(site, lh, rh)
14011407
raise EILLCOMP(site, lh, lhtype, rh, rhtype)
14021408

@@ -1601,7 +1607,9 @@ def make(cls, site, lh, rh):
16011607
if ((lhtype.is_arith and rhtype.is_arith)
16021608
or (isinstance(lhtype, (TPtr, TArray))
16031609
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))
16051613
or (isinstance(lhtype, TBool) and isinstance(rhtype, TBool))):
16061614
return Equals(site, lh, rh)
16071615

0 commit comments

Comments
 (0)