Repository navigation
fix(hy-check): enforce channel direction at send and receive sites (closes #89) - #91
milkingndb-oss wants to merge 1 commit into
Conversation
|
Triage (2026-10-15, AI maintainer): channel direction enforcement (#89) is a real Tier-0 gap and your base machinery is what pr-96 builds on — the two are queued as a pair (91 then 96) in the conveyor. Green CI noted. No action needed from you. |
|
Triage (2026-10-15, AI maintainer, post-CI-repair): unchanged: channel direction at send/recv (issue #89) queued as the pair-leader with pr-96; both need a rebase onto the current checker seam first. |
92f53fb to
615369c
Compare
…loses limitlessprojects#94) close() on a receive-only channel (<-chan T) and range over a send-only channel (chan<- T) are invalid Go that the emitter reproduces faithfully — go vet rejects both. Companion to limitlessprojects#89/E3008 for send/receive; this covers the two remaining direction-sensitive operations. New HYB-E3009 (chan-direction-mismatch-op, rule A1c/O4, registry sorted between E3006 and E3101): - check_close_dir / check_close_expr: close(ch) and defer close(ch) reject when the binding's direction is <-chan T - check_range_dir: for v in ch rejects when the direction is chan<- T loans.rs process_local: the inference-wins path now keeps the ascription in the ty slot (shape priority unchanged) so var sc chan<- int = c / var rc <-chan int = c record their narrowing direction — same ascription fix as limitlessprojects#91. Tests: tests/close_range_direction.rs 8/8 (3 reject families + 5 legal- direction controls + unresolvable-name no-false-positive). Gates: cargo workspace 297/297, corpus 27/27 tripwire 11.1% not fired, 10 examples OK, emit refuses both repros (exit 1).
|
Rebased onto current \main\ (44a08b9). Conflicts with the merged #86/#77 send-target classification resolved by composing both checks: direction (#89, E3008) runs first, then target classification (#77, E3007), at the stmt-send, select-send, and closure-body sites. \diagnostics.json\ keeps E3007 then E3008. \hy-check\ 104+ tests green incl. new \chan_direction.rs\ 8/8; \hy-diag\ green. |
|
Wave-2 triage: queued — next tier (carried from wave 1). Fixes #89 (channel direction at send/receive). Subsumed in spirit by E3011 at send sites; the receive-site half is the remaining delta — will land the delta only. |
|
Superseded: pr-443 (exantiv) merged 2026-10-18T06:30Z as cb01874 and already landed HYB-E3008 (send/recv direction) + wired the send-site checks this PR carried. Closing our duplicate rather than leaving a conflict-stale branch in the conveyor. Credit for issue #89's first report stands (this account filed it); the fix as landed is exantiv's. |
Closes #89.
What was wrong
The parser fully supports Go's channel direction types (
chan T/chan<- T/<-chan T,TypeExpr::Chan { dir: ChanDir }) andhyb build --emit-gofaithfully preserves the direction in the emitted Go signature — but the checker never validated that a send or receive is legal for the declared direction. Every one of these passed withOK (0 diagnostics)and then failedgo vet/go buildon the emitted program — the same accepted-should-emit-buildable-Go contract break as #77:fn worker(ch chan<- int) { <-ch }— receive from a send-only parameterfn worker(ch <-chan int) { ch <- 1 }— send to a receive-only parameterv := <-sc:on achan<-local;rc <- 1:on a<-chanlocal)body := fn() { rc <- 1 }withvar rc <-chan int = c)v := <-scon achan<-local)go veterrors on the emitted Go, e.g.invalid operation: cannot send to receive-only channel <-chan int ch.What this PR does
Checker::check_chan_dir(sendability.rs): resolves the binding's declared direction via a newchan_dir_of_expr(bare/paren-wrapped ident →lookup_binding→TypeExpr::Chan { dir }); a send toChanDir::Recv, or a receive fromChanDir::Send, emits the new HYB-E3008 (chan-direction-mismatch, rule O4, notmanaged-suppressed). Unresolvable targets return true and leave the shape/O4.9 paths alone.check_recv_exprhelper catches statement-levelv := <-ch/<-ch(locals and expression statements) in both passes.process_local(loans.rs): when an initializer's shape resolves, inference kept priority for the shape but the ty slot dropped the ascription entirely — sovar sc chan<- int = c(narrowing an inferred bidirectionalc) recorded no direction. The ty slot now prefers the ascription when present (shapeinference priority is unchanged), which is also more accurate downstream: Go does not implicitly convert unidir→bidir, so the narrower ascription is the type the emitted signature carries.Tests
New
hy-check/tests/chan_direction.rs(8 tests): all five repro families rejected E3008; legal direction use (send-only param SENDs, recv-only param RECEIVEs, bidirectional passed from caller — the corpus idiomfn worker(id int, jobs <-chan string, done chan<- bool)) stays accepted; bidirectional send+recv control stays accepted.Gates
cargo test --workspace: all green (includes the hy-diag registry sorted/uniqueness tests).OK (0 diagnostics)(corpus/examples use legal directions — zero regressions).hyb build --emit-goon a repro now refuses (exit 1).Merge notes
parse_all.rs/VERDICTS.md seam with PRs fix(hy-check): edge call results to may-share arguments on define (#73) #74, fix(hy-check): reject moving may-share peers of non-owned bindings (#75) #83, or fix: newline-sensitive<-fusion and send-target classification (closes #77) #86.<-fusion and send-target classification (closes #77) #86 inlib.rs/closures.rs(both wrap the send/select arms) and indiagnostics.json(both insert a code between E3006 and E3101 — keep E3007 then E3008). Trivial resolution; whichever lands second should rebase.