diff options
author | kostya-sh <kostya-sh@users.noreply.github.com> | 2017-10-17 16:25:27 +0100 |
---|---|---|
committer | alandonovan <adonovan@google.com> | 2017-10-17 11:25:27 -0400 |
commit | 25a152db3440891960758ed4d9d5b0fdf308d4ba (patch) | |
tree | eefb557ce02c4273889d942d1acef12b5191c497 | |
parent | 6a8b65efdff4c536ba7ac2d71c8ef02fad27b1c6 (diff) | |
download | starlark-go-25a152db3440891960758ed4d9d5b0fdf308d4ba.tar.gz |
skylark: do not leave zip arguments frozen (#5)
-rw-r--r-- | library.go | 7 | ||||
-rw-r--r-- | testdata/builtins.sky | 6 |
2 files changed, 13 insertions, 0 deletions
@@ -1036,6 +1036,13 @@ func zip(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error) } rows, cols := 0, len(args) iters := make([]Iterator, cols) + defer func() { + for _, iter := range iters { + if iter != nil { + iter.Done() + } + } + }() for i, seq := range args { it := Iterate(seq) if it == nil { diff --git a/testdata/builtins.sky b/testdata/builtins.sky index 9fe7c91..2f845db 100644 --- a/testdata/builtins.sky +++ b/testdata/builtins.sky @@ -104,6 +104,12 @@ assert.eq(zip(list("abc".split_bytes()), list("def".split_bytes()), list("hijk".split_bytes())), [("a", "d", "h"), ("b", "e", "i"), ("c", "f", "j")]) +z1 = [1] +assert.eq(zip(z1), [(1,)]) +z1.append(2) +assert.eq(zip(z1), [(1,), (2,)]) +assert.fails(lambda: zip(z1, 1), "zip: argument #2 is not iterable: int") +z1.append(3) # dir for builtins assert.eq(dir(None), []) |