forked from M-Labs/artiq
compiler: Fix type inference for "ternary" if expressions
Previously, any type would be accepted for the test expression, leading to internal errors in the code generator if the passed value wasn't in fact a bool.
This commit is contained in:
parent
888696f588
commit
b8cd163978
|
@ -305,6 +305,7 @@ class Inferencer(algorithm.Visitor):
|
|||
|
||||
def visit_IfExpT(self, node):
|
||||
self.generic_visit(node)
|
||||
self._unify(node.test.type, builtins.TBool(), node.test.loc, None)
|
||||
self._unify(node.body.type, node.orelse.type,
|
||||
node.body.loc, node.orelse.loc)
|
||||
self._unify(node.type, node.body.type,
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
# RUN: %python -m artiq.compiler.testbench.inferencer %s >%t
|
||||
# RUN: OutputCheck %s --file-to-check=%t
|
||||
|
||||
# CHECK-L: def foo(val:bool)->numpy.int?:
|
||||
def foo(val):
|
||||
return 1 if val else 0
|
Loading…
Reference in New Issue