compiler: support methods defined on singleton instances.

Fixes #638.
This commit is contained in:
whitequark 2017-01-30 10:10:21 +00:00 committed by Sebastien Bourdeauducq
parent 1845a134e5
commit 2dc8d417ca
2 changed files with 27 additions and 1 deletions

View File

@ -561,7 +561,11 @@ class StitchingInferencer(Inferencer):
# of having the host-to-ARTIQ mapping code in only one place and # of having the host-to-ARTIQ mapping code in only one place and
# also immediately getting proper diagnostics on type errors. # also immediately getting proper diagnostics on type errors.
attr_value = getattr(object_value, attr_name) attr_value = getattr(object_value, attr_name)
if inspect.ismethod(attr_value) and types.is_instance(object_type): if (inspect.ismethod(attr_value) and
types.is_instance(object_type) and
# Check that the method is indeed defined on the class,
# and not just this instance.
hasattr(type(attr_value), attr_name)):
# In cases like: # In cases like:
# class c: # class c:
# @kernel # @kernel

View File

@ -0,0 +1,22 @@
# RUN: %python -m artiq.compiler.testbench.embedding %s
from artiq.language.core import *
from artiq.language.types import *
class a:
def foo(self, x):
print(x)
class b:
def __init__(self):
self.obj = a()
self.meth = self.obj.foo
@kernel
def run(self):
self.meth(1)
bi = b()
@kernel
def entrypoint():
bi.run()