From ad2ee714c29d662665ee0ed1859fbeb918a12b18 Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 9 Jun 2017 07:29:08 +0000 Subject: [PATCH] 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. --- artiq/compiler/transforms/inferencer.py | 2 +- artiq/test/lit/inferencer/error_str_iter.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 artiq/test/lit/inferencer/error_str_iter.py diff --git a/artiq/compiler/transforms/inferencer.py b/artiq/compiler/transforms/inferencer.py index 0003f214e..c4fb07b94 100644 --- a/artiq/compiler/transforms/inferencer.py +++ b/artiq/compiler/transforms/inferencer.py @@ -183,7 +183,7 @@ class Inferencer(algorithm.Visitor): if builtins.is_bytes(collection.type) or builtins.is_bytearray(collection.type): self._unify(element.type, builtins.get_iterable_elt(collection.type), 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_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/inferencer/error_str_iter.py b/artiq/test/lit/inferencer/error_str_iter.py new file mode 100644 index 000000000..a79c52f83 --- /dev/null +++ b/artiq/test/lit/inferencer/error_str_iter.py @@ -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]