Skip to content

fix: newline statement boundary for send and validate send channel target (fixes #77) - #78

Closed
rickymulya wants to merge 1 commit into
limitlessprojects:mainfrom
rickymulya:fix-issue-77-send-target-and-newline-fusion
Closed

rickymulya wants to merge 1 commit into
limitlessprojects:mainfrom
rickymulya:fix-issue-77-send-target-and-newline-fusion

Conversation

@rickymulya

Copy link
Copy Markdown
Contributor

Summary

Fixes #77.

Resolves two cooperating gaps that allowed multi-line expressions and receive statements to merge into invalid sends, and allowed send statements targeting non-channel expressions to pass the type checker without diagnostics.

Root Cause & Changes

  1. Parser Newline Statement Separation (hy-syntax):
    Under SPEC-LANGUAGE.md LX9, statements are line-terminated and the parser is newline-sensitive where statements would otherwise merge. In parse_simple_stmt, when checking self.at_punct("<-"), we now verify that the <- operator is on the same line as the preceding expression (self.toks[self.pos].span.start.line == self.toks[self.pos - 1].span.end.line). If <- is on a subsequent line, the preceding expression statement completes (e.g. noop()), and <-done is parsed as a new statement (Stmt::Expr receive).
  2. Send Channel Target Proof (hy-check):
    Under SPEC-LANGUAGE.md §8.4 and O4.9 (fail-closed boundary), the channel target of a channel send statement/clause must resolve to a channel shape. We pass send_chan: Option<&Expr> into check_site. If the LHS expression does not resolve to TypeShape::Chan(_), it is treated as unproven/invalid, emitting HYB-E3005 (or HYB-E8001 inside managed).
  3. Tests:
    • hy-syntax: added send_does_not_fuse_across_newline.
    • hy-check: added send_to_void_call_callee_is_fail_closed_e3005, send_to_non_channel_local_is_fail_closed_e3005, and repro_issue_77_two_line_receive_compiles_cleanly.

…rget (fixes limitlessprojects#77)

- hy-syntax: ensure `<-` is on the same line as the channel expression in
  `parse_simple_stmt` so that a preceding expression statement (e.g. `noop()`)
  and a subsequent receive expression (e.g. `<-done`) on the next line do not
  fuse into a bogus send statement `noop() <- done` across lines (LX9).
- hy-check: validate that the channel target expression of a send statement
  resolves to `TypeShape::Chan(_)`; if it is non-channel or unresolvable,
  emit `HYB-E3005` fail-closed (or `HYB-E8001` inside `managed`) (§8.4 / O4.9).
- tests: add parser test `send_does_not_fuse_across_newline` and checker tests
  `send_to_void_call_callee_is_fail_closed_e3005`, `send_to_non_channel_local_is_fail_closed_e3005`,
  and `repro_issue_77_two_line_receive_compiles_cleanly`.
@limitlessprojects

Copy link
Copy Markdown
Owner

Landed on main — the Batch U merge fixes both halves of #77. Honest seam note: the port took the shape of your independent fix (same-line parser guard + target classification at all four send shapes, your parser test's scenario included) but #86's diagnostic design won the seam — a dedicated HYB-E3007 with a registry entry for concrete non-channels instead of folding everything into unproven/E3005, since an ill-typed TARGET is a type contract, not a sendability doubt (your fail-closed instinct for unresolvable targets is preserved exactly there — E3005/O4.9). Verified: repro A parses as two statements and builds; repro C rejects; same-line sends unchanged. Closing as landed with credit — thank you.

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