mirror of https://github.com/m-labs/artiq.git
compiler: unbreak subscripts for bytes values (#714).
This commit is contained in:
parent
66a683f583
commit
5b4fde30a8
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue