forked from M-Labs/artiq
1
0
Fork 0

compiler: do not permit iterating str values.

This currently breaks badly on UTF-8, and doesn't even return
a value of a correct type.
This commit is contained in:
whitequark 2017-06-09 07:29:08 +00:00
parent 4e7493843a
commit ad2ee714c2
2 changed files with 6 additions and 1 deletions

View File

@ -183,7 +183,7 @@ class Inferencer(algorithm.Visitor):
if builtins.is_bytes(collection.type) or builtins.is_bytearray(collection.type): if builtins.is_bytes(collection.type) or builtins.is_bytearray(collection.type):
self._unify(element.type, builtins.get_iterable_elt(collection.type), self._unify(element.type, builtins.get_iterable_elt(collection.type),
element.loc, None) element.loc, None)
elif builtins.is_iterable(collection.type): elif builtins.is_iterable(collection.type) and not builtins.is_str(collection.type):
rhs_type = collection.type.find() rhs_type = collection.type.find()
rhs_wrapped_lhs_type = types.TMono(rhs_type.name, {"elt": element.type}) rhs_wrapped_lhs_type = types.TMono(rhs_type.name, {"elt": element.type})
self._unify(rhs_wrapped_lhs_type, rhs_type, self._unify(rhs_wrapped_lhs_type, rhs_type,

View File

@ -0,0 +1,5 @@
# RUN: %python -m artiq.compiler.testbench.inferencer +diag %s >%t
# RUN: OutputCheck %s --file-to-check=%t
# CHECK-L: ${LINE:+1}: error: type str is not iterable
("a")[0]