Skip to content

fix(hy-check): reject nil consts and support f32/f64/char and string aliases in const_init.rs - #671

Open
sonson0910 wants to merge 1 commit into
limitlessprojects:mainfrom
sonson0910:fix/const-init-nil-f32-f64-paren-composite-and-str-alias
Open

sonson0910 wants to merge 1 commit into
limitlessprojects:mainfrom
sonson0910:fix/const-init-nil-f32-f64-paren-composite-and-str-alias

Conversation

@sonson0910

@sonson0910 sonson0910 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #670

Summary

Fixes 4 HYB-E6003 soundness and false-positive bugs in compiler/crates/hy-check/src/const_init.rs:

  1. LitKind::Nil in const initializers: Rejects Expr::Lit { kind: LitKind::Nil, .. } in expr_is_constant_inner so const e error = nil is rejected with HYB-E6003 instead of emitting invalid Go (nil is not constant).
  2. SPEC float and char conversion spellings (f32, f64, char): Adds "f32", "f64", and "char" to is_conversion_type_name so const a = f64(42), const b = f32(1.5), and type my_char = char; const c = my_char(65) are accepted.
  3. Typed file-level const in is_const_string_expr: Checks cdecl.ty so const s any = "hello"; const n = len(s) is rejected with HYB-E6003.
  4. string type aliases and shadowing inside len(...): Resolves type aliases and checks for shadowing in is_const_string_conversion_target so type my_str = string; const n = len(my_str("hello")) is accepted while type string = int; const n = len(string(65)) is rejected with HYB-E6003.

Verification

  • cargo test --workspace passes with 4 new regression tests in compiler/crates/hy-check/tests/const_init_soundness.rs.

@sonson0910
sonson0910 force-pushed the fix/const-init-nil-f32-f64-paren-composite-and-str-alias branch from 2421c5e to 74cfdad Compare October 18, 2026 15:19
@sonson0910 sonson0910 changed the title fix(hy-check): reject nil and parenthesized composite consts, and support f32/f64/char and string aliases in const_init.rs fix(hy-check): reject nil consts and support f32/f64/char and string aliases in const_init.rs Oct 18, 2026
milkingndb-oss pushed a commit to milkingndb-oss/Go-Hybrid that referenced this pull request Oct 18, 2026
… := nil / let x = nil) with HYB-E4003, the N1 untyped leg (fixes limitlessprojects#672)

The E4001 nil check at both local-declaration sites was ascription-gated
(if let Some(t) = &l.ty): with no ascription, shape_of_expr(nil) is
Unknown, the checker accepted the declaration with 0 diagnostics, and the
emitter emitted �ar x = nil / x := nil — which Go rejects outright
(use of untyped nil in variable declaration). Accepted-but-unbuildable
(GUARANTEES row 13, BUILDABLE).

- new registry code HYB-E4003 untyped-nil-declaration (rule N, tier0 N1):
  nil's two homes (error, foreign perimeter) must be visible in a
  DECLARED type; an untyped nil can never name either. Three fix routes:
  ascribe the nil home; declare without initializer for the zero value
  (N3); option[T] for absence.
- loans.rs process_local: else-branch on the E4001 ascription gate emits
  E4003 for bare-nil initializers of var/let/:= (flat walk covers
  loop/match-arm/if-block bodies).
- closures.rs check_stmt_boundaries: same else-branch for closure bodies.
- local const c = nil is left to the E6003 constant-expression guard
  (issue limitlessprojects#640 / PR limitlessprojects#671) — Go's error there is 'nil is not constant';
  the two loci do not double-fire.
- 13 unit pins (hy-check/tests/untyped_nil_decl.rs): four spellings,
  closure/loop/match-arm/blank; controls that stay accepted (ascribed
  error-nil, bare nil as call argument/compare, zero-value declarations).
- corpus fixture untyped-nil-decl-reject.hy (REJECT N1, exact diagnostic
  HYB-E4003) registered in VERDICTS.md; corpus 80/80, tripwire not fired;
  differential reject-side 57/57; cargo workspace 1150/0.

Co-Authored-By: opencode <noreply@opencode.ai>
@sonson0910
sonson0910 force-pushed the fix/const-init-nil-f32-f64-paren-composite-and-str-alias branch from 74cfdad to 0a99a6e Compare October 18, 2026 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug][hy-check] const_init.rs accepts nil and non-string typed consts in len(s), and rejects f32/f64/char and string aliases

1 participant