mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-24 19:04:02 +08:00
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
|
||||
|
9
artiq/test/lit/codegen/error_illegal_return.py
Normal file
9
artiq/test/lit/codegen/error_illegal_return.py
Normal file
@ -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)
|
9
artiq/test/lit/codegen/unreachable_implicit_return.py
Normal file
9
artiq/test/lit/codegen/unreachable_implicit_return.py
Normal file
@ -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
Block a user