From f35f10011091ccffe7d2cc02c7681367b49ff1e6 Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 28 Apr 2018 00:49:25 +0000 Subject: [PATCH] compiler: don't crash printing locations of specialized functions. Fixes #987. --- artiq/compiler/embedding.py | 5 +++++ .../lit/embedding/error_specialized_annot.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 artiq/test/lit/embedding/error_specialized_annot.py diff --git a/artiq/compiler/embedding.py b/artiq/compiler/embedding.py index 6cee76bf9..e72adeee2 100644 --- a/artiq/compiler/embedding.py +++ b/artiq/compiler/embedding.py @@ -749,6 +749,11 @@ class Stitcher: quote_function=self._quote_function) def _function_loc(self, function): + if isinstance(function, SpecializedFunction): + function = function.host_function + if hasattr(function, 'artiq_embedded'): + function = function.artiq_embedded.function + filename = function.__code__.co_filename line = function.__code__.co_firstlineno name = function.__code__.co_name diff --git a/artiq/test/lit/embedding/error_specialized_annot.py b/artiq/test/lit/embedding/error_specialized_annot.py new file mode 100644 index 000000000..c474f235b --- /dev/null +++ b/artiq/test/lit/embedding/error_specialized_annot.py @@ -0,0 +1,19 @@ +# RUN: %python -m artiq.compiler.testbench.embedding +diag %s 2>%t +# RUN: OutputCheck %s --file-to-check=%t + +from artiq.experiment import * + +class c(): +# CHECK-L: ${LINE:+2}: error: type annotation for argument 'x', 'None', is not an ARTIQ type + @kernel + def hello(self, x: None): + pass + + @kernel + def run(self): + self.hello(2) + +i = c() +@kernel +def entrypoint(): + i.run()