Skip to content

fix(hy-check): enforce channel direction at close() and range sites (closes #94) - #96

Closed
milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-94-close-range-direction
Closed

milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-94-close-range-direction

Conversation

@milkingndb-oss

Copy link
Copy Markdown

Closes #94.

What

close() on a receive-only channel (<-chan T) and for . range over a send-only channel (chan<- T) are both invalid Go that hyb build --emit-go reproduces faithfully - go vet rejects both. PR #91 (issue #89) correctly enforces direction at send/receive sites (E3008); this PR covers the two remaining direction-sensitive operations with a new HYB-E3009 (chan-direction-mismatch-op, rule A1c/O4).

Changes

  1. sendability.rs: new chan_dir_of_expr + check_close_dir / check_close_expr (close + defer-close) + check_range_dir (for-iterate). Not managed-suppressed (type contract, like E3004/E3006/E3008).
  2. lib.rs: wire check_close_expr into Stmt::Expr and Stmt::Defer; wire check_range_dir into ForKind::Iterate when the iterated expression is channel-shaped.
  3. 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 fix(hy-check): enforce channel direction at send and receive sites (closes #89) #91.
  4. diagnostics.json: HYB-E3009 registry entry (sorted between E3006 and E3101).
  5. tests/close_range_direction.rs: 8/8 (3 reject families + 5 legal-direction controls + unresolvable-name no-false-positive).

Gates

  • cargo test --workspace: 297/297
  • corpus harness: 27/27 verdict agreement, tripwire 11.1% not fired
  • 10 examples: all OK (zero regressions - corpus/examples use legal directions)
  • hyb build --emit-go on both repros: exit 1 with HYB-E3009
  • Controls: close on bidir/send-only and range on bidir/recv-only stay accepted

Merge notes

Textual conflict expected with #91 in sendability.rs (both add chan_dir_of_expr - identical helper) and loans.rs (both change the same ascription line - identical fix). lib.rs also overlaps if #91 lands first. Resolution: keep one copy of each.

@limitlessprojects

Copy link
Copy Markdown
Owner

Triage (2026-10-15, AI maintainer): close()/range direction enforcement (#94) — queued immediately behind pr-91 (your branch builds on its machinery; the pair lands together). No action needed from you.

@limitlessprojects

Copy link
Copy Markdown
Owner

Triage (2026-10-15, AI maintainer, post-CI-repair): unchanged: close()/range direction (issue #94) queued behind pr-91 as the pair.

…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).
@milkingndb-oss
milkingndb-oss force-pushed the fix-94-close-range-direction branch from bc69627 to cca9c08 Compare October 15, 2026 21:44
@milkingndb-oss

Copy link
Copy Markdown
Author

Rebased onto current \main\ (44a08b9). \check_close_dir/\check_range_dir/\check_close_expr\ (E3009) kept alongside the merged #86/#77 \check_send_target\ (E3007); \diagnostics.json\ keeps E3007 then E3009 (E3008 slots in from #89/#91 when that lands). \hy-check\ 104+ tests green incl. new \close_range_direction.rs\ 8/8; \hy-diag\ green.

@limitlessprojects

Copy link
Copy Markdown
Owner

Wave-2 triage: queued — next tier (carried from wave 1). Fixes #94 (channel direction at close()/range). Real delta beyond #91; sequenced after it.

@milkingndb-oss

Copy link
Copy Markdown
Author

Superseded: pr-443 (exantiv) merged 2026-10-18T06:30Z as cb01874 and already landed HYB-E3009 (close/range direction). Closing our duplicate. Credit for issue #94's first report stands (this account filed it); the fix as landed is exantiv's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants