mirror of https://github.com/m-labs/artiq.git
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
ca6db87895
commit
01352236ee
|
@ -305,6 +305,7 @@ class Inferencer(algorithm.Visitor):
|
||||||
|
|
||||||
def visit_IfExpT(self, node):
|
def visit_IfExpT(self, node):
|
||||||
self.generic_visit(node)
|
self.generic_visit(node)
|
||||||
|
self._unify(node.test.type, builtins.TBool(), node.test.loc, None)
|
||||||
self._unify(node.body.type, node.orelse.type,
|
self._unify(node.body.type, node.orelse.type,
|
||||||
node.body.loc, node.orelse.loc)
|
node.body.loc, node.orelse.loc)
|
||||||
self._unify(node.type, node.body.type,
|
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