diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index b94985463..db6b06723 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -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", diff --git a/artiq/test/lit/embedding/error_with_rpc.py b/artiq/test/lit/embedding/error_with_rpc.py new file mode 100644 index 000000000..4f0fce23e --- /dev/null +++ b/artiq/test/lit/embedding/error_with_rpc.py @@ -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