Skip to content

fix(hy-check): keyword-name checks on enums, dotted associated fns, import aliases (fixes #4190) - #4278

Open
kotomuch wants to merge 2 commits into
limitlessprojects:mainfrom
kotomuch:fix-4190-keyword-names
Open

kotomuch wants to merge 2 commits into
limitlessprojects:mainfrom
kotomuch:fix-4190-keyword-names

Conversation

@kotomuch

@kotomuch kotomuch commented Nov 9, 2026

Copy link
Copy Markdown

Summary

Extends the go_keyword_names pass (HYB-E1002, Row 13 BUILDABLE) to three declaration surfaces that previously bypassed the default/none detector (fixes #4190).

Root Cause & Defect

compiler/crates/hy-check/src/go_keyword_names.rs enforced keyword-name hygiene on locals, params, receivers, structs, aliases, consts, fields, loop vars, select/match bindings — but missed:

  1. Decl::Enum skipped entirely (matched to {} alongside Import): enum default { … }, variant names (enum state { default }), and payload types carrying default/none passed check with 0 diagnostics, then failed hyb build (hy-emit spells enum names/variants verbatim).
  2. Dotted associated-function names: self.kw_name(&f.name, …) compared the full dotted string ("box.default", "default.build") against the keyword — never equal, so associated fns named default/none in either segment bypassed the check.
  3. Decl::Import unhandled: non-Rust imports register the trailing path segment as the Go package identifier (lib.rs rsplit; emission root.Member() in hy-emit), so import "x/default" produced unparseable Go.

Changes

  • Decl::Enum: enum name ("enum"), each variant name ("enum variant"), payload types via kw_type.
  • Decl::Fn: split f.name on . and check each segment (dotted receiver-associated names).
  • Decl::Import: for !path.starts_with("rust/") check the trailing segment ("package import"); rust/ crates keep their separate registration rule (prefix-rooted, not trailing-segment).
  • Doc comment updated (enum variants are no longer left alone).

Tests

New compiler/crates/hy-check/tests/go_keyword_enum_dotted_import_names.rs (harness mirrors go_keyword_default_names.rs):

  • 6 negative tests: enum/variant/none variants, payload traversal (fn param + struct field through enum payload), dotted box.default/box.none/default.build, import aliases (x/default, y/none, bare default);
  • 2 positive controls: dotted clean segment (box.defaults), rust/ import, clean alias (x/fallback), plain fmt.

Test names listed 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: programs declaring enums/dotted-fns/imports named default or none — previously accepted, then failing go build (Row 13 violations, exactly the class this pass closes). Existing valid programs unaffected (positive controls pin rust/ imports and clean names).

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

@kotomuch
kotomuch force-pushed the fix-4190-keyword-names branch 2 times, most recently from 11f7267 to d5e8eb1 Compare November 9, 2026 20:27
@github-actions github-actions Bot added the bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) label Nov 9, 2026
@kotomuch
kotomuch force-pushed the fix-4190-keyword-names branch from d5e8eb1 to 74fc63f Compare November 9, 2026 23:25
… 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
…mport aliases (fixes limitlessprojects#4190)

Three declaration surfaces bypassed HYB-E1002 (default/none):

- Decl::Enum was skipped entirely: enum names, variant names, and
  payload types now go through kw_name/kw_type.
- Decl::Fn dotted names (box.default, default.build) compared the
  whole string against the keyword; each dot-segment is checked now.
- Decl::Import unhandled: non-rust imports register the trailing path
  segment as the Go package identifier, so it is keyword-checked;
  rust/ crates keep their separate registration rule.

Doc comment updated (enum variants are no longer left alone).
New tests: go_keyword_enum_dotted_import_names.rs (7 tests, harness of
go_keyword_default_names.rs).
@kotomuch
kotomuch force-pushed the fix-4190-keyword-names branch from 74fc63f to d5cf9ee Compare November 10, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify())

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[soundness] hy-check(go_keyword_names): reject default/none on Decl::Enum, associated functions, and Decl::Import (HYB-E1002)

1 participant