forked from M-Labs/artiq
Add support for BoolOp.
This commit is contained in:
parent
b8ce3f85bd
commit
4b7d4c2425
|
@ -301,18 +301,24 @@ class Inferencer(algorithm.Transformer):
|
|||
|
||||
def visit_BoolOp(self, node):
|
||||
node = self.generic_visit(node)
|
||||
for value, op_loc in zip(node.values, node.op_locs):
|
||||
node = asttyped.BoolOpT(type=types.TVar(),
|
||||
op=node.op, values=node.values,
|
||||
op_locs=node.op_locs, loc=node.loc)
|
||||
def makenotes(printer, typea, typeb, loca, locb):
|
||||
return [
|
||||
diagnostic.Diagnostic("note",
|
||||
"py2llvm requires boolean operations to have boolean operands", {},
|
||||
op_loc)
|
||||
"an operand of type {typea}",
|
||||
{"typea": printer.name(node.values[0].type)},
|
||||
node.values[0].loc),
|
||||
diagnostic.Diagnostic("note",
|
||||
"an operand of type {typeb}",
|
||||
{"typeb": printer.name(typeb)},
|
||||
locb)
|
||||
]
|
||||
self._unify(value.type, types.TBool(),
|
||||
value.loc, None, makenotes)
|
||||
return asttyped.BoolOpT(type=types.TBool(),
|
||||
op=node.op, values=node.values,
|
||||
op_locs=node.op_locs, loc=node.loc)
|
||||
for value in node.values:
|
||||
self._unify(node.type, value.type,
|
||||
node.loc, value.loc, makenotes)
|
||||
return node
|
||||
|
||||
# Visitors that just unify types
|
||||
#
|
||||
|
|
|
@ -11,3 +11,8 @@ a = b
|
|||
[1, []]
|
||||
# CHECK-L: note: a list of type list(elt=int(width='a))
|
||||
# CHECK-L: note: a list element of type list(elt='b)
|
||||
|
||||
# CHECK-L: ${LINE:+1}: error: cannot unify int(width='a) with bool
|
||||
1 and False
|
||||
# CHECK-L: note: an operand of type int(width='a)
|
||||
# CHECK-L: note: an operand of type bool
|
||||
|
|
|
@ -38,3 +38,6 @@ j += [1.0]
|
|||
|
||||
True and False
|
||||
# CHECK-L: True:bool and False:bool:bool
|
||||
|
||||
1 and 0
|
||||
# CHECK-L: 1:int(width='g) and 0:int(width='g):int(width='g)
|
||||
|
|
Loading…
Reference in New Issue