Repository navigation
Description
Two sub-families of "accepted with 0 diagnostics, emitted Go fails go vet/go build" on current main (c09e992). Both are trivially reachable from ordinary source and neither is covered by any open issue/PR I can find (searched make/builtin/defer/E2003/E2004; #98/#99 are freeze/loan-across-defer - different failure mode; #178 copy-may-share - different).
Sub-family A - builtin argument validation is absent
Every shape below passes hyb check with OK (0 diagnostics) on main c09e992, and the emitted Go fails go build / go vet:
| # | repro | emitted Go | go build/vet error |
|---|---|---|---|
| A1 | fn main() { c := make(chan int, -1) } |
c := make(chan int, -1) |
invalid argument: index -1 (constant of type int) must not be negative |
| A2 | fn main() { c := make(chan int, "x") } |
c := make(chan int, "x") |
cannot convert "x" (untyped string constant) to type int |
| A3 | fn main() { s := make([]int, -1) } |
s := make([]int, -1) |
invalid argument: index -1 (constant of type int) must not be negative |
| A4 | fn main() { c := make(chan int, 2.5) } |
c := make(chan int, 2.5) |
2.5 (untyped float constant) truncated to int |
| A5 | fn main() { close(5) } |
close(5) |
invalid operation: cannot close non-channel 5 (untyped int constant) |
| A6 | fn main() { fmt.println(cap("x")) } |
fmt.Println(cap("x")) |
invalid argument: "x" (untyped string constant) for built-in cap |
| A7 | fn main() { fmt.println(len(5)) } |
fmt.Println(len(5)) |
invalid argument: 5 (untyped int constant) for built-in len |
| A8 | fn main() { m := map[string]int{"a": 1}; delete(m) } |
delete(m) |
not enough arguments in call to delete(m) (expected 2, found 1) |
Controls that must KEEP parsing (and do today): make(chan int, n) with an ident size, len("abc") (Go: valid - string has a length), len(m) on maps/slices/chans, delete(m, k), close(ch) on an ident.
The literal-only scope keeps this the same shape as the landed #149/#163 const-arith checks (HYB-E6001/E6002): reject the compile-time-detectable literal misuse; run-time misuse (make(chan int, n) with a variable that happens to be -1) stays a run-time panic, matching Go.
Sub-family B - defer accepts non-call expressions; registry code HYB-E2001 exists but is never raised
diagnostics.json already registers HYB-E2001 defer-non-call ("defer requires a call expression") - but grep shows the code is never constructed anywhere in hy-check (no E2001 in any .rs). So the documented diagnostic has zero enforcement:
fn main() { ch := make(chan int, 1); defer ch <- 1; fmt.println("ok") }- OK (0 diagnostics). The parser's statement-level<-fusion (checker+parser: expression statement fused with a next-line<-chreceive into a send (noop() <- done) - accepted with 0 diagnostics, emitted Go does not compile; send targets are never classified #77 guard) does not apply insidedefer'sparse_expr, so this parses asStmt::Defer{call: Ident(ch)}followed by a receive statement<- 1. The emitter emits:? vet:defer ch <-1
expression in defer must be function call(line 9) +invalid operation: cannot receive from non-channel untyped int 1(line 10). Two errors from one accepted statement.fn main() { ch := make(chan int, 1); ch <- 7; defer <-ch; fmt.println("ok") }- OK (0 diagnostics). Emitsdefer <-ch? build:syntax error: unexpected <-, expected expression/ vet:expression in defer must be function call.
Go's grammar requires defer's operand to be a function call (CallExpr); defer ch <- x and defer <-ch are compile errors in Go. Hybrid's own AST documents the intended form (/// defer f.close()?) - Expr::Call (and Try wrapping a call) should be the only accepted shapes.
Suggested fix direction
- Wire HYB-E2001 where
Stmt::Deferis walked: after unwrappingParen/Try, the operand must beExpr::Call; otherwise raise the already-registered diagnostic with its existing fix-it ("defer the call itself:defer f.close()?"). - New registry code (E2003/E2004 are claimed by open PR fix(hy-check): validate '?' operand error shape and propagation scope (fixes #155) #167; E2005 is free) for builtin-argument validation: an
arith.rs-style walker (check_stmt_builtin_call) coveringmake(arity 1-2; size literal must be a non-negative int - Str/Float/Bool/Char/negative-Int reject),len/cap(arity 1; Int/Float/Bool/Char literal operand reject;lenof Str/RawStr stays valid,capof string rejects),delete(arity exactly 2),close(arity 1; literal operands reject - literals can never be channels),new(literal operand rejects -newtakes a type).
Both families match the maintainer's landed pattern for this class (#149?E6001, #148?E6002, #103?while reservation): accepted-but-unbuildable emission gets a check-time rejection with a teachable message.
Repro dir (probe .hy + emitted .go.go side by side): %TEMP%\opencode\hunt\p2-*.hy.
Activity
fix(hy-check): restore limitlessprojects#187 branch so it auto-merges…
fix(hy-check): reject invalid builtin args and defer non-calls (#187)
Merge pr-191 (salvocanci, fixes limitlessprojects#187): defer non-cal…
Merge pr-430 (hardik4love-lang, fixes limitlessprojects#425; twin PR l…