forked from M-Labs/artiq
compiler: reject reachable implicit return if not returning TNone.
Fixes #718.
This commit is contained in:
parent
c33f9637c1
commit
032f28863f
|
@ -317,7 +317,15 @@ class ARTIQIRGenerator(algorithm.Visitor):
|
|||
self.current_block.append(ir.Return(ir.Constant(None, builtins.TNone())))
|
||||
else:
|
||||
if not self.current_block.is_terminated():
|
||||
if len(self.current_block.predecessors()) != 0:
|
||||
diag = diagnostic.Diagnostic("error",
|
||||
"this function must return a value of type {typ} explicitly",
|
||||
{"typ": types.TypePrinter().name(typ.ret)},
|
||||
node.keyword_loc)
|
||||
self.engine.process(diag)
|
||||
|
||||
self.current_block.append(ir.Unreachable())
|
||||
|
||||
finally:
|
||||
self.name = old_name
|
||||
self.current_args = old_args
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
# RUN: %python -m artiq.compiler.testbench.signature +diag %s >%t
|
||||
# RUN: OutputCheck %s --file-to-check=%t
|
||||
|
||||
# CHECK-L: ${LINE:+1}: error: this function must return a value of type numpy.int32 explicitly
|
||||
def foo(x):
|
||||
if x:
|
||||
return 1
|
||||
|
||||
foo(True)
|
|
@ -0,0 +1,9 @@
|
|||
# RUN: %python -m artiq.compiler.testbench.signature %s
|
||||
|
||||
def foo(x):
|
||||
if x:
|
||||
return 1
|
||||
else:
|
||||
return 2
|
||||
|
||||
foo(True)
|
Loading…
Reference in New Issue