Skip to content

checker+parser: expression statement fused with a next-line <-ch receive into a send (noop() <- done) - accepted with 0 diagnostics, emitted Go does not compile; send targets are never classified #77

Open

Description

@milkingndb-oss

Revision (git rev-parse HEAD)

8fb92385a54f3934959c1ff059cb13f2ffe2e78d (origin/main, 2026-10-14 19:51 UTC).

Summary

Two cooperating gaps turn an ordinary-looking Hybrid snippet into a program that hyb check accepts with OK (0 diagnostics) and hyb build --emit-go then emits as invalid Go (the emitted file does not compile - "accepted ? emits a compiling program" is broken):

  1. Parser (newline-insensitive send fusion): an expression statement followed by a line that starts with a receive expression is parsed as ONE send statement. noop() / newline / <-done becomes noop() <- done. Go avoids this with automatic semicolon insertion; the Hybrid parser appears to treat <- as a continuation of the previous expression regardless of the line break.
  2. Checker (send target never classified): even a deliberate one-line noop() <- 1 - a send whose channel expression is a void call - is accepted with 0 diagnostics. Nothing validates that the LHS of a send statement resolves to a chan shape (a known non-channel should be a type error; an unresolvable one is at least O4.9 fail-closed HYB-E3005).

Either gap alone yields accepted-invalid-emission; fixing (2) also rejects the accidental fusion from (1), so it is the safety net.

Minimal repro A - accidental fusion (the footgun)

// probe-fuse.hy (main @ 8fb9238)
fn noop() {
}

fn main() {
    done := make(chan bool, 1)
    noop()
    <-done
}

hyb check probe-fuse.hy ? OK (0 diagnostics).
hyb build probe-fuse.hy --emit-go emits:

func main() {
	done := make(chan bool, 1)
	noop() <- done
}

go build on the emitted file: ./main.go:8:2: noop() (no value) used as value.

Real-world shape: any helper call followed by a <-done drain on the next line (the single most common wait idiom in the corpus/examples) fuses if the helper takes no channel-shaped continuation on the same line.

Minimal repro B - deliberate send-to-non-channel (checker gap)

// probe4.hy (main @ 8fb9238)
fn noop() {
}

fn main() {
    noop() <- 1
}

hyb check probe4.hy ? OK (0 diagnostics); emission is noop() <- 1 - again invalid Go. The send's target is statically a void call (known non-channel) - this must not be OK under any reading: A1c never gets a chance to run because the site is not even well-typed.

Expected

  • Repro A: parse as two statements (noop(); receive-expr statement), check accepts the plain program (the drain is legal), emission keeps them separate - same as noop() / ch <- 1 already does today (see control below).
  • Repro B: reject with a type/boundary error (a non-chan send target - HYB-E3005 fail-closed at minimum if the shape is unresolvable; a concrete "cannot send to " diagnostic when it resolves to a call/primitive).

Actual

OK (0 diagnostics)

for both; emitted Go does not compile in both cases.

Severity

Not a data race - no concurrency hazard is reachable through these two programs (the emission fails to build instead). Claimed as a correctness/claim bug: an accepted program must at minimum emit buildable Go. Happy for the maintainer to re-derive (P1 "ownership violation without a race" does not apply either; closest bucket is the accepted-should-have-been-rejected family).

Anything else

  • Control that already works: noop() followed by ch <- 1 (send statement starting with the channel ident) emits correctly as two statements - the fusion is specific to a following line beginning with the <- receive form.
  • Another fusion variant seen incidentally while reducing a separate repro: outer(h, done) / newline / <-done emitted as outer(h, done) <- done (same root).
  • Possible fix directions (not prescriptive): newline/;-sensitivity in the statement parser when an expression statement is followed by <- (Go ASI-style), and/or statement-level send classification (Expr::Send. whatever the AST spells it - the emit path already has a send form) that resolves the LHS shape and errors on non-chan.
  • Caught while reducing [soundness] Moving a may-share peer of a parameter escapes the O5.1 non-owned check (h2 := h; task worker(move h2) - OK accepted, fatal error: concurrent map writes) #75's repro - the r := <-done spelling was needed to dodge this fusion, which is how the two were noticed together.
  • AI-assisted report (MiMo agent via opencode); reporter of record: @milkingndb-oss.

Activity

  1. rickymulya commented on Oct 14, 2026

    @rickymulya
    Contributor

    Opened fix PR #78 addressing both gaps:

    1. hy-syntax: line boundary check prevents multi-line expressions and receive statements from fusing across lines (parse_simple_stmt, LX9).
    2. hy-check: send channel target proof fails closed (HYB-E3005) when the target expression does not resolve to TypeShape::Chan(_) (§8.4, O4.9).

    Includes regression tests in hy-syntax and hy-check covering the two-line repro and fail-closed diagnostics.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions