Skip to content

while cond { } silently accepted as ident+expr+block - emitted Go fails go vet (undefined: while); reserve while like mut #103

Closed

Description

@milkingndb-oss

Summary

while is not a Hybrid keyword and not reserved by the lexer, so while cond { … } silently parses as an identifier expression while, followed by expression cond, followed by a separate block statement. hyb check accepts it with 0 diagnostics; the emitter faithfully emits the ident + cond + orphan block as Go, and the emitted program fails go vet/go build with undefined: while.

This is the exact same class as the mut bug that was fixed by reserving mut in the KEYWORDS list (lexer.rs — the comment there documents the precedent). while was left unreserved.

Repro

fn main() {
    x := 1
    while x > 0 {
        x += 1
    }
    fmt.println(x)
}
  • hyb check while-only.hy → OK (0 diagnostics)
  • hyb build while-only.hy --emit-go → emits:
func main() {
	x := 1
	while          // vet: undefined: while
	x > 0
	{
		x += 1
	}
	fmt.Println(x)
}
  • go vet on the emitted file: undefined: while

Controls

  • for x > 0 { … } — Hybrid's actual while-form (ForKind::While) — accepted and emits valid Go for x > 0 { … }. This is the correct spelling.
  • loop { … } / for v in 0..n { … } — unaffected.

Suggested fix

Add while to the lexer KEYWORDS list (lexer.rs:74-116) and either:

  1. Reject at parse with a clear diagnostic ("while is not a Hybrid keyword — use for cond { … } (while-form) or loop { … }"), mirroring how other reserved words behave; or
  2. Accept as a while-loop (ForKind::While) — but only if the grammar deliberately wants a while alias; the docs/spec use for cond { }, so option 1 (reject) is the minimal honest fix and matches the mut precedent (keyword reserved, parse-level error, no silent bad emission).

Either way the failure mode changes from "accepted → invalid Go" to a proper parse/check-time diagnostic.

Environment

  • commit: 8fb9238 (origin/main) — repro re-verified on the fix-100-loop-label-scope build c8b0609 (unrelated fix; while bug present there too)
  • Windows, rustc stable, go1.26.9

Activity

  1. added a commit that references this issue on Oct 15, 2026
    12e943b
  2. added a commit that references this issue on Oct 15, 2026
    efb6061
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