You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[soundness] for x in e never type-checks the iterable — ranging over an int / bool / struct / non-iterable call result is accepted with 0 diagnostics and emits non-compiling Go (cannot range over) #411
8dd00028c7791813e56c586a3b77192bd57db2d8 (origin/main, 2026-10-17; hyb built from this exact tree, rustc 1.99.0 x86_64-pc-windows-gnu).
Summary
SPEC-LANGUAGE LX13 pins the iterable set: "for x in e iterates slices, arrays, strings (runes), maps (keys), channels (until close), and integer ranges for i in 0..n." Nothing checks that the e in for x in e actually belongs to that set. Every shape below passes hyb check with OK (0 diagnostics) on current main, and the emitted Go fails go build:
#
repro
emitted Go
go build error
R1
x := 5; for v in x { }
for _, v := range x
cannot range over x (variable of type int)
R2
fn f() int {…}; for v in f() { }
for _, v := range f()
cannot range over f() (value of type int)
R3
b := true; for v in b { }
for _, v := range b
cannot range over b (variable of type bool)
R4
s := box{…}; for v in s { } (struct)
for _, v := range s
cannot range over s (variable of type box)
Controls that must KEEP passing (and do today): for k in m over a map ✓, for i in 0..n (the integer-range form is a different ForKind and is not affected) ✓, slices/arrays/strings/channels ✓.
Root cause
The checker never classifies the ForKind::Iterate { expr } operand. arith.rs / builtins.rs walk it for their own concerns, and walk.rs collects its uses, but no pass asks the one question LX13 requires: is this a slice/array/string/map/channel?shape_of_expr already resolves the operand — the same data check_send_target consumes for send targets (#77) and my #409 proposes for receive operands. The Range { lo, hi } form is unaffected (no iterable operand); only Iterate is open.
Related but disjoint: #94/#96 (channel direction at range/close sites — <-chan T vs chan<- T), #298/#285 (range lowering in the emitter). This report is about the iterable's kind — an int was never legal in the position at all.
Suggested fix direction
One check_range_iterable(st, expr, span) mirroring the #77 send-target classification: Slice/Array/Str/Map/Chan → fine; concrete non-iterable (Primitive, named struct, Bool, …) → reject with the LX13 rule ("for x in e iterates slices, arrays, strings, maps, and channels — not {}"); Unknown → the same fail-closed treatment the send/receive sides use (O4.9). Wire it wherever ForKind::Iterate is visited (Tier-0 flat walk + the closure walk, the A5 perimeter).
Claimed severity
Medium (BOUNTY.md "accepted-but-unbuildable" track, same family as #187/#149/#148/#409): four everyday shapes pass 0-diagnostics and emit Go that fails go build.
Report prepared with AI assistance (WorkBuddy agent); all verdicts reproduced mechanically against main @ 8dd00028 — hyb check + hyb build --emit-go on each .hy quoted above.
unresolvable iterable → fail-closed HYB-E3005 (O4.9), symmetric with the other two sides
whitelist includes BorrowHandle (the L3 borrow views corpus 07/11/12 iterate); for i in 0..n (ForKind::Range) is a different statement kind and stays untouched
One finding the whitelist alone misses, worth flagging for every fix candidate on this issue: generic instantiation folds type arguments into the name string (lru_cache[k, v] parses as the single name "lru_cache[k, v]" — TypeExpr has no type-argument node), so a receiver fn (c *lru_cache[k, v]) touch(...) classified as Pointer(Unknown) and its declared []k field resolved Unknown. Any whitelist check without a shape-layer fix therefore fail-closes for i, e in c.order (spike6-07) as E3005 and fails the existing spike6_programs_all_accept_with_zero_errors test — verifiable with cargo test -p hy-check --test spike6_positive. This PR resolves struct/alias lookups through the base name in named_shape_depth and adds a pin for the generic-receiver case.
8 new pins (5 reject / 3 accept incl. the generic-receiver guard); full workspace green except the pre-existing gofmt-dependent test (no Go toolchain locally).
Activity
gelismarvel commentedon Oct 17, 2026
/claim #411
Fixes #411
Submitting verified fix PR for #411.
for x in enever type-checks the iterable — ranging over an int / bool / struct / non-iterable call result is accepted with 0 diagnostics and emits non-compiling Go (cannot range over) (#411) #426 (fix: resolvefor x in enever type-checks the iterable — ranging over an int / bool / struct / non-iterable call result is accepted with 0 diagnostics and emits non-compiling Go (cannot range over) (#411) #426)hardik4love-lang commentedon Oct 17, 2026
/claim #411
Fixes #411
Submitting verified comprehensive fix PR #427:
Implementation Highlights in #427:
fix(hy-check): emit HYB-E2009 for non-iterable range and keep Unknown…
Leimiu-G commentedon Oct 17, 2026
/claim #411
Fixes #411
Submitting verified fix PR — #447: #447
The classification mirrors the send-target (#77) / receive-operand (#409) family one-for-one:
non-iterable-range, dedicated new code — not E2005, which is the builtins literal/arity diagnostic fix: resolvefor x in enever type-checks the iterable — ranging over an int / bool / struct / non-iterable call result is accepted with 0 diagnostics and emits non-compiling Go (cannot range over) (#411) #426 reuses; not E2008, which open PR check: type-check receive operands (HYB-E2008/E3005) — the receive-side mirror of #77's send-target rule (fixes #409) #420 registers asreceive-non-channel)BorrowHandle(the L3 borrow views corpus 07/11/12 iterate);for i in 0..n(ForKind::Range) is a different statement kind and stays untouchedOne finding the whitelist alone misses, worth flagging for every fix candidate on this issue: generic instantiation folds type arguments into the name string (
lru_cache[k, v]parses as the single name"lru_cache[k, v]"— TypeExpr has no type-argument node), so a receiverfn (c *lru_cache[k, v]) touch(...)classified asPointer(Unknown)and its declared[]kfield resolvedUnknown. Any whitelist check without a shape-layer fix therefore fail-closesfor i, e in c.order(spike6-07) as E3005 and fails the existingspike6_programs_all_accept_with_zero_errorstest — verifiable withcargo test -p hy-check --test spike6_positive. This PR resolves struct/alias lookups through the base name innamed_shape_depthand adds a pin for the generic-receiver case.8 new pins (5 reject / 3 accept incl. the generic-receiver guard); full workspace green except the pre-existing gofmt-dependent test (no Go toolchain locally).
fix(check): type-check for-in iterable operands and reject non-iterab…
fix: resolve `for x in e` never type-checks the iterable — ranging ov…
fix(hy-check): emit HYB-E2009 for non-iterable range and keep Unknown…
fix(check): type-check for-in iterable operands and reject non-iterab…
fix(check): type-check for-in iterables (HYB-E2009/E3005) and resolve…
Merge pr-447 (Leimiu-G, fixes limitlessprojects#411): type-check for-…
Merge pr-288 (Leimiu-G): defer-operand E2001 with closure wiring; hoi…
fix(checker): time.after deadline channels accepted a send — emitted …
fix(checker): time.after deadline channels accepted a send — emitted …
fix(checker): time.after deadline channels accepted a send — emitted …
fix(checker): time.after deadline channels accepted a send — emitted …
fix(checker): time.after deadline channels accepted a send — emitted …
fix(checker): time.after deadline channels accepted a send — emitted …
fix(checker): time.after deadline channels accepted a send — emitted …