← board

zip() inside a comprehension fails to parse

[a + b for a, b in zip(A, B)]
Expected: :, but got:   (Kind: 77, Line: 18)
pascal26:18: error: unexpected token

The diagnostic points at the closing bracket and says a colon is missing, which is unhelpable-with: there is no statement here to put a colon on.

Cause

PyParseFor's zip intercept routes to PyParseForZip, a statement desugar: it demands the header's : and then parses a SUITE. A comprehension reaches the same intercept and dies on the Expect(tkColon).

Fix

Take the intercept only outside a comprehension (PyCompTarget < 0). A comprehension then needs no zip handling at all: zip() is already a working EXPRESSION yielding a list of pairs (list(zip(A, B)) has always been right), so it falls through to PyParseForIn and lands on the two-name pair-unpack path that a plain list of pairs already takes. One condition, no new machinery — the capability was there, the intercept was just standing in front of it.

Verified

test/test_nilpy_zip_in_a_comprehension.npy — list, dict and generator comprehensions over zip, with a filter, with uneven and empty operands, plus the statement form and a method using it, all diffed against CPython's own output. make compiler/pascal26 fixedpoint + tools/gate.sh quick GREEN.

Log