Skip to content

fix(hy-check): validate call arity and reject non-callable symbols on errors (fixes #4171) - #4277

Open
kotomuch wants to merge 1 commit into
limitlessprojects:mainfrom
kotomuch:fix-4171-errors-arity
Open

kotomuch wants to merge 1 commit into
limitlessprojects:mainfrom
kotomuch:fix-4171-errors-arity

Conversation

@kotomuch

@kotomuch kotomuch commented Nov 9, 2026

Copy link
Copy Markdown

Summary

Extends hy-check buildable validation to the errors package call surface (fixes #4171, GUARANTEES Row 13 BUILDABLE).

Root Cause & Defect

In compiler/crates/hy-check/src/buildable.rs, call checking for errors package members validated only errors.wrap (dedicated #3572 operand checks). The other curated members passed with zero diagnostics regardless of shape:

  1. Arity bypass: errors.new, errors.unwrap, errors.is, errors.as, errors.join accepted any argument count — accepted programs fail go build with Go's signature errors.
  2. Non-callable variable: errors.err_unsupported (a package-level variable mapping errors.ErrUnsupported) was accepted as a call target.

Both violate Row 13: hy check accepts → go build fails (HYB-E1002 class).

Changes

New check_errors_call_buildable collector pass (hooked alongside the merged io pass #4204), enforcing the Go contract:

Member Contract
new, unwrap exactly 1 argument
is, as exactly 2 arguments (err, target)
join at least 1 argument
err_unsupported not callable (variable)
wrap unchanged — dedicated operand validation (#3572) stays authoritative

Shadowing safety: the pass only fires when self.lookup_kind(pkg).is_none() (same guard as the io pass) — an in-scope errors declaration is never touched.

Tests

New compiler/crates/hy-check/tests/errors_call_buildable_soundness.rs:

  • 6 negative tests: arity rejects for new/unwrap/is/as/join, non-callable err_unsupported();
  • 1 positive control: correct new/unwrap/join calls plus value reference errors.err_unsupported accept with zero errors.

All new tests mirror the harness of the merged io_call_buildable_soundness.rs. Test names are listed here rather than runner counts: no local cargo on this machine; fork CI and your battery are the verification loop — happy to fix anything they flag.

Cost honesty

What breaks: nothing that compiled before — programs that passed hy check and go build with correct errors usage still pass (positive control pins this). Corpus: unchanged (zero corpus fixtures used errors misuse).

Disclosure: Authored by an autonomous coding agent; the account owner has reviewed the patch and stands behind every line.

… errors (fixes limitlessprojects#4171)

- errors.new/unwrap: exactly 1 argument
- errors.is/as: exactly 2 arguments
- errors.join: at least 1 argument
- errors.err_unsupported: variable, not callable (HYB-E1002)
- errors.wrap keeps dedicated operand validation (limitlessprojects#3572), unchanged
- new regression tests in errors_call_buildable_soundness.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant