Skip to content

fix: newline-sensitive <- fusion and send-target classification (closes #77) - #86

Closed
milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-77-send-target-classification
Closed

milkingndb-oss wants to merge 1 commit into
limitlessprojects:mainfrom
milkingndb-oss:fix-77-send-target-classification

Conversation

@milkingndb-oss

Copy link
Copy Markdown

Closes #77.

What was wrong

Two cooperating gaps turned ordinary snippets into programs that hyb check accepted with 0 diagnostics and hyb build --emit-go then emitted as invalid Go (noop() <- done — noop() (no value) used as value), breaking the accepted-subset contract that every accepted program emits buildable Go.

  1. Parser fused a next-line <- into the previous expression statement. Hybrid has no Go-style automatic semicolon insertion, so noop() on one line and <-done on the next fused into a single Stmt::Send (noop() <- done). In Go, a statement starting with <-expr is a receive; a <- on a new line never continues the previous statement.
  2. Send targets were never classified. chan_elem_shape only classified the sent value; nothing required the channel expression to resolve to a channel shape. A deliberate noop() <- 1 (void call as target) passed with 0 diagnostics.

What this PR does

  • Parser (hy-syntax): the expression-statement <- fusion now requires the <- token to sit on the same source line as the end of the expression list (Parser::same_line_as_prev, using the existing line/col spans — no lexer change). A next-line <- starts a receive-expression statement of its own. Sends whose value wraps onto the next line still parse as one send.
  • Checker (hy-check): new Checker::check_send_target (sendability.rs) classifies every send target before the value check-site:
    • resolves to chan T → proceed as before;
    • resolves to a concrete non-channel → new HYB-E3007 (send-target-not-channel, registry entry added, rule O4/A1c, fail-fast — the value check is skipped since the site is ill-typed);
    • unresolvable shape → HYB-E3005 (O4.9 fail-closed).
      Like E3004/E3006, an ill-typed target is not a sendability doubt — managed does not suppress it.
  • Wired into all four send paths: statement sends and select-arm sends (lib.rs), plus their closure-body twins (closures.rs).

Tests

  • hy-syntax parser tests: newline before a receive does not fuse; same-line ch <- 1 still fuses; a wrapped send value stays one send.
  • New hy-check/tests/send_target.rs (6 tests): the newline-recv drain idiom is two statements and accepted; the void-call send is rejected (E3005/E3007); a map target is rejected E3007; select-arm and closure-body twins are rejected; a real channel send + drain stays accepted.

Gates

  • cargo test --workspace: all green.
  • Checker corpus harness: 29/29, tripwire not fired (as-written managed 10.3% < ~25% threshold).
  • All 11 example programs: OK (0 diagnostics).
  • Emission spot-check: the de-fused repro now emits noop() and <-done as two statements; hyb build on the map-target repro refuses (exit 1).

Merge note

Corpus numbering: this PR adds no corpus files (its repros live in unit/integration tests), so it does not touch parse_all.rs or VERDICTS.md and has no merge seam with PR #74 (slot 28) or PR #83 (slots 29–30).

@limitlessprojects

Copy link
Copy Markdown
Owner

Landed on main — the Batch U merge carries your port in full: the same_line_as_prev() parser guard, check_send_target with the dedicated HYB-E3007 registry entry (your fixits, including the "a statement starting with <- is a RECEIVE" lesson), the no-cascade bool, all four send shapes wired, and send_target.rs. Verified against the report: repro A now parses as two statements and the emitted Go builds; repro C rejects; same-line sends unchanged. rickymulya's #78 independently fixed the same two halves with a leaner diagnostic story — your E3007 + registry entry won on teachability; both of you are credited on the merge. Closing as landed.

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