diff --git a/artiq/compiler/builtins.py b/artiq/compiler/builtins.py index 9965f5284..a64129dcc 100644 --- a/artiq/compiler/builtins.py +++ b/artiq/compiler/builtins.py @@ -285,15 +285,13 @@ def is_exception(typ, name=None): typ.name == name def is_iterable(typ): - typ = typ.find() - return isinstance(typ, types.TMono) and \ - typ.name in ('list', 'array', 'range') + return is_listish(typ) or is_range(typ) def get_iterable_elt(typ): - if is_iterable(typ): - return typ.find()["elt"].find() - elif is_str(typ) or is_bytes(typ): + if is_str(typ) or is_bytes(typ): return TInt(types.TValue(8)) + elif is_iterable(typ): + return typ.find()["elt"].find() else: assert False diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 9a3cbd0ed..d6a23a36e 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -180,7 +180,10 @@ class Inferencer(algorithm.Visitor): self.engine.process(diag) def _unify_iterable(self, element, collection): - if builtins.is_iterable(collection.type): + if builtins.is_bytes(collection.type): + self._unify(element.type, builtins.TInt(), + element.loc, None) + elif builtins.is_iterable(collection.type): rhs_type = collection.type.find() rhs_wrapped_lhs_type = types.TMono(rhs_type.name, {"elt": element.type}) self._unify(rhs_wrapped_lhs_type, rhs_type, diff --git a/artiq/test/lit/integration/subscript.py b/artiq/test/lit/integration/subscript.py index eaa7f8455..f0398be4c 100644 --- a/artiq/test/lit/integration/subscript.py +++ b/artiq/test/lit/integration/subscript.py @@ -17,3 +17,7 @@ assert lst[0:3:2] == [0, 2] lst = [0, 0, 0, 0, 0] lst[0:5:2] = [1, 2, 3] assert lst == [1, 0, 2, 0, 3] + +byt = b"abc" +assert byt[0] == 97 +assert byt[1] == 98