Skip to content

fix(hy-check): reject declarations named none, the option constructor (HYB-E1002, Row 13) - #3798

Merged
limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
RPMFAN:fix-none-predeclared-declarations
Nov 7, 2026
Merged

limitlessprojects merged 1 commit into
limitlessprojects:mainfrom
RPMFAN:fix-none-predeclared-declarations

Conversation

@RPMFAN

@RPMFAN RPMFAN commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

What happens (main @ 3d029ca)

SPEC LX3 lists none as a predeclared identifier. hy-emit, however, treats every bare Ident none as the option constructor (return none against a declared option[T], or not yet supported: none outside a return anywhere else). A declaration that steals the name therefore passes check and fails build:

fn main() {
    none := 1
    fmt.println("{none}")
}
$ hyb check t.hy
t.hy: OK (0 diagnostics)
$ hyb build t.hy -o t
error [emit]: emitter (MVP-0): not yet supported: `none` outside a return (MVP-0 lowers `return none` against the declared option result)

The same accept-then-fail shape hits locals (:= / var), params, named results, receivers, type params, fn / method names, struct fields, aliases, consts, for-in / range variables, select-receive names, match bindings, and closure params. Each is an accepted program that does not build — GUARANTEES Row 13.

Fix

Extend the existing go_keyword_names pass (the default walk from #3677) so a declaration named none is HYB-E1002, e.g. local named `none` — `none` is Hybrid's option constructor, so hy-emit cannot treat the name as an ordinary binding and `hyb build` fails.

return none and match arms none: / none => are not declarations, so they stay accepted. Names that merely contain the word (none_val, is_none) and a shadowed some stay accepted.

Alternative considered: teach hy-emit to honour a shadowed none (SPEC's "shadowable with a lint"). That needs full scope tracking at every Ident site and interacts with #1657 (lower unbound none in value positions to the option zero). Rejecting at check fails closed, matches how default was handled, and can be relaxed later if emit learns to shadow.

Not a duplicate of #1657 / #1298 (emit lowering of unbound none as option zero) — those implement the constructor; this rejects declarations that steal the name.

Tests

New compiler/crates/hy-check/tests/go_keyword_none_names.rs, 2 tests:

  • every_declaration_site_named_none_is_rejected — 17 programs, one per site (mirrors the default matrix)
  • option_none_surface_and_similar_names_stay_accepted — return none, match arms, none_val / is_none, .or / .is_none(), shadowed some

Existing go_keyword_default_names.rs suite still green.

Verification (local; rustc 1.85.1, HYB_PINNED_RUST=1.85.1 HYB_ALLOW_TOOLCHAIN_DRIFT=1)

  • cargo test -p hy-check --test go_keyword_none_names --test go_keyword_default_names: 2 + 2 passed, 0 failed.

Diff: 2 files, +114 / −0.

Payout Wallet (USDC on Base / EVM): 0x26AB46a0309C3ab8F2f59754B3066e77E8154A34

@cursor
cursor Bot force-pushed the fix-none-predeclared-declarations branch from 6d478f7 to c43d3db Compare November 6, 2026 12:12
@github-actions github-actions Bot added the bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) label Nov 6, 2026
@cursor
cursor Bot force-pushed the fix-none-predeclared-declarations branch 5 times, most recently from f8f854b to ce6d0e2 Compare November 6, 2026 20:39
…YB-E1002)

hy-emit treats every bare Ident `none` as the option constructor, so a
declaration named `none` (local, param, fn, field, …) passed hyb check
with 0 diagnostics and then failed hyb build with `not yet supported:
none outside a return` (GUARANTEES Row 13). Reject each declaration site
the same way as `default` (limitlessprojects#3677). `return none` and match arms `none:` /
`none =>` are not declarations and stay accepted.

Regression tests in hy-check/tests/go_keyword_none_names.rs.
@cursor
cursor Bot force-pushed the fix-none-predeclared-declarations branch from ce6d0e2 to 32cd931 Compare November 6, 2026 21:30
@limitlessprojects
limitlessprojects merged commit 7cdea0a into limitlessprojects:main Nov 7, 2026
2 of 3 checks passed
@limitlessprojects

Copy link
Copy Markdown
Owner

Landed in 7cdea0a0 — merged into main (Session 131 drain, 2026-11-07)

Thank you @RPMFAN — this is landed with a merge credit commit CREDIT: @RPMFAN.

What landed (PR head 32cd9310, clean auto-merge into current main):

  • go_keyword_names.rs: the kw_name gate now rejects any declaration named none with HYB-E1002 before the GO_ONLY_KEYWORD check. Rationale carried in the diagnostic: hy-emit spells every bare Ident none as the option constructor and refuses it outside return none against an option result, so a none declaration passed check and then failed hyb build (GUARANTEES Row 13). Fail-closed at declaration sites until emit learns to honour shadowing; return none and match arms none: / none => are not declarations and stay accepted (the fix(hy-emit): lower none in value positions to the declared option[T] zero value (fixes #1297) #1657 unbound-none lowering is a different niche).
  • New suite go_keyword_none_names covering the declaration-site mix with accept controls.

Verification evidence (trial-merge worktree vs main @ bee05086, full battery):

  • merge gate: CLEAN
  • cargo test --workspace: 460 suites ok, 0 failed
  • corpus harness: 135/135, tripwire not fired
  • differential loop: 45/45 accept + 90/90 reject — FULL AGREEMENT
  • post-merge tree asserted against the trial-merge tree (53a724e9); origin/main == local HEAD after push (7cdea0a0).

Bounty rail: per BOUNTY.md / discussion #295 — eligibility recorded with this landing.

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.

2 participants