Skip to content

[soundness] operand types are never checked: non-boolean if/for conditions, operator/operand mismatches, index/slice/call of non-indexables, and binding-shaped builtin misuse all accepted with 0 diagnostics and emit unbuildable Go #425

Closed

Description

@honru09

Revision

c53978bd33734169fa5299f5ac3eaf4c3c325fb9 (origin/main, 2026-10-17). hyb built from this tree (rustc 1.85.1), emitted Go built with the pinned go1.26.9.

Summary

Outside the ownership rules, the checker never asks whether an operand has a type its operator accepts. Every program below is a plain fn main() { ... } that hyb check accepts with OK (0 diagnostics). hyb build --emit-go emits it, and go build fails with the quoted error. There are five families, and none overlaps an open issue (see "Not duplicates").

# body of fn main() go build error on the emitted Go
A. Non-boolean conditions
A1 x := 5 / if x { fmt.println(1) } non-boolean condition in if statement
A2 x := 5 / for x { x = 0 } non-boolean condition in for statement
B. Operator / operand type mismatch
B1 x := 5 / fmt.println(!x) operator ! not defined on x (variable of type int)
B2 s := "a" / fmt.println(-s) operator - not defined on s (variable of type string)
B3 x := 5 / s := "a" / fmt.println(x + s) invalid operation: x + s (mismatched types int and string)
B4 x := 5 / fmt.println(x && true) invalid operation: x && true (mismatched types int and untyped bool)
B5 b := true / fmt.println(b < false) operator < not defined on bool
B6 s := "a" / s++ / fmt.println(s) invalid operation: s++ (non-numeric type string)
C. Index / slice of a non-indexable value
C1 x := 5 / fmt.println(x[0]) cannot index x (variable of type int)
C2 x := 5 / fmt.println(x[0:1]) cannot slice x (variable of type int)
D. Calling a non-function
D1 x := 5 / fmt.println(x()) cannot call x (variable of type int): int is not a function
E. Builtin operand kind via a binding (#187 deliberately covered literals only)
E1 x := 5 / fmt.println(len(x)) invalid argument: x (variable of type int) for built-in len
E2 x := 5 / close(x) cannot close non-channel x (variable of type int)
E3 m := map[string]int{} / fmt.println(cap(m)) invalid argument: m (variable of type map[string]int) for built-in cap
E4 xs := []int{1} / delete(xs, 0) / fmt.println(xs) invalid argument: xs (variable of type []int) is not a map
E5 x := 5 / x = append(x, 1) / fmt.println(x) invalid append: argument must be a slice; have x (variable of type int)

(/ separates lines. Each repro is its own file, e.g. fn main() {\n x := 5\n if x { fmt.println(1) }\n}.)

Repro loop: hyb check f.hy → f.hy: OK (0 diagnostics); hyb build f.hy -o out/bin --emit-go; cd out && go mod init p && go build . → the error above.

Expected

Each shape gets a Hybrid diagnostic with a span. For the builtins (E) that is an extension of #187's BUILTIN-ARGS rule from literals to resolved binding shapes. A–D need a new BUILDABLE code or codes. In every case shape_of_expr already resolves the operand (Primitive / Str / Map / Slice ...), which is the same data #77 (send target), #409 (receive operand) and #411 (range iterable) classify. The fix is one operand-kind check per operator site, and Unknown stays on the existing fail-closed path.

Controls that must keep passing: if ok {} with a bool, !b, -n, a + b on two ints or two strings, xs[i], s[0:1], m[k], f() on a fn binding, len(s), len(m), cap(xs), close(ch), delete(m, k), append(xs, v).

Not duplicates

Claimed severity

Medium, in the accepted-but-unbuildable family (same track as #187/#152/#409/#411). These are the most ordinary beginner mistakes, and each surfaces as raw Go compiler output instead of a Hybrid diagnostic.

Activity

  1. hardik4love-lang commented on Oct 17, 2026

    @hardik4love-lang

    /claim #425
    Fixes #425

    Submitting verified comprehensive fix PR #430 (submitted at 11:38:06Z, #1 in queue):

    Implementation Highlights in #430:

    1. Operand Type Validation: Comprehensive validation in emit_guard.rs for conditions (if/ or conditions must be boolean -> HYB-E2009), unary - and ! operands, index/slice target validation (non-slice/map/string/array -> HYB-E2009), and call target validation (non-callable targets -> HYB-E2009).
    2. Binding-Shaped Builtin Checking: Validates arguments to built-in calls (len, close, cap, delete, �ppend) routed through bindings, emitting HYB-E2005 on shape mismatches.
    3. Registered Diagnostic: HYB-E2009 registered in diagnostics.json with clear explanations and help hints.
    4. Test Suite: Comprehensive suite covering all 5 defect families with negative test pins and positive controls in ests/operand_types.rs.
  2. added a commit that references this issue on Oct 17, 2026
    c8468be
  3. added a commit that references this issue on Oct 17, 2026
  4. Suifeng-2077 commented on Oct 17, 2026

    @Suifeng-2077
    Contributor

    Measured the two open takes against this issue's own reproduction set, on real builds.

    I built hyb from main and from each PR head with the repo pins (Go 1.26.9, rust 1.99.0), then ran all 16 shapes from the table above plus 4 positive controls (if ok {} on a bool, -n on an int, xs[0], len(m)). ACCEPT means hyb check returns 0 diagnostics, which is the bug this issue describes.

    build accepted rejected still erroneously accepted
    main 20 0 all 16
    #430 11 9 A1, A2, B1, B6
    #431 4 16 none - the 4 accepted are exactly the controls

    Corpus regression on the same binaries: #430 52/52, #431 52/52, tripwire not fired on either, so neither take trades coverage for new over-rejection.

    So #431 closes all five families (A-E) and keeps the controls intact; #430 closes C, D and E, and part of B, but leaves non-boolean if/for and the !/++ operator mismatches accepted even though its title covers conditions. The two touch disjoint files (emit_guard.rs + a new test module vs buildable.rs), so this is a coverage difference rather than a duplicate - but #431 alone satisfies the issue as written.

    Scope: this compares behaviour only. I did not review either patch for correctness beyond what the battery and the corpus show, and the diagnostic codes differ between the two (HYB-E2009/HYB-E2005 in #430, HYB-E1002/HYB-E2005 in #431), which is a policy choice for the maintainer, not mine.

  5. added 2 commits that reference this issue on Oct 17, 2026
    c3948a0
    c10f33a
  6. hardik4love-lang commented on Oct 17, 2026

    @hardik4love-lang

    @Suifeng-2077 @limitlessprojects

    Thank you for the benchmarking data! As the #1 queue submitter (submitted at 11:38:06Z), I have updated PR #430 in commit c10f33a (cleanly rebased onto current upstream main @ 07d63ec):

  7. added 3 commits that reference this issue on Oct 17, 2026
    6a4fb46
    d29aa32
    52aeb21
  8. added a commit that references this issue on Oct 18, 2026
    2eb4049
  9. added a commit that references this issue on Oct 18, 2026
    7dc16e8
  10. honru09 commented on Oct 18, 2026

    @honru09
    ContributorAuthor

    Hi, I'm the reporter of this issue. Saw it got closed via #430 — nice work on the fix.

    Just wanted to check: as the first reporter of #425, does the issue bounty still count for me? Want to make sure I understand how the reporting reward works when someone else's PR lands the fix.

  11. added a commit that references this issue on Oct 18, 2026
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