2
0
mirror of https://github.com/m-labs/artiq.git synced 2025-02-07 16:15:22 +08:00

compiler: Report non-kernel __enter__/__exit__ methods

Signed-off-by: Jonathan Coates <jonathan.coates@oxionics.com>
This commit is contained in:
Jonathan Coates 2025-01-30 20:10:14 +00:00 committed by GitHub
parent 0f0f030267
commit c50f3a1c12
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -1674,7 +1674,14 @@ class Inferencer(algorithm.Visitor):
else:
typ = typ.find()
if not (len(typ.args) == arity and len(typ.optargs) == 0):
if not types.is_function(typ):
diag = diagnostic.Diagnostic("error",
"function '{attr}{attr_type}' must be a @kernel",
{"attr": attr_name,
"attr_type": printer.name(typ)},
node.loc)
self.engine.process(diag)
elif not (len(typ.args) == arity and len(typ.optargs) == 0):
diag = diagnostic.Diagnostic("error",
"function '{attr}{attr_type}' must accept "
"{arity} positional argument{s} and no optional arguments",

View File

@ -0,0 +1,20 @@
# RUN: %python -m artiq.compiler.testbench.embedding +diag %s 2>%t
# RUN: OutputCheck %s --file-to-check=%t
from artiq.experiment import kernel
class contextmgr:
def __enter__(self):
pass
@kernel
def __exit__(self, n1, n2, n3):
pass
c = contextmgr()
@kernel
def entrypoint():
# CHECK-L: ${LINE:+1}: error: function '__enter__[rpc2 #](...)->NoneType' must be a @kernel function
with c:
pass