forked from M-Labs/artiq
1
0
Fork 0

compiler: Fix type inference in slice expressions

This was a long-standing issue affecting both lists and
the new NumPy array implementation, just caused by the
generic inference passes not being run on the slice
subexpressions (and thus e.g. ints not being monomorphized).

GitHub: Fixes #1632.
This commit is contained in:
David Nadlinger 2021-03-14 18:46:28 +00:00
parent 75c255425d
commit 557671b7db
2 changed files with 20 additions and 0 deletions

View File

@ -216,6 +216,7 @@ class Inferencer(algorithm.Visitor):
value.loc, None)
def visit_SliceT(self, node):
self.generic_visit(node)
if (node.lower, node.upper, node.step) == (None, None, None):
self._unify(node.type, builtins.TInt32(),
node.loc, None)

View File

@ -0,0 +1,19 @@
# RUN: %python -m artiq.compiler.testbench.embedding %s
from artiq.language.core import *
from artiq.language.types import *
import numpy as np
class A:
def __init__(self):
self.n = 2
@kernel
def run(self):
print([1, 2, 3][:self.n])
a = A()
@kernel
def entrypoint():
a.run()