Repository navigation
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
Conversation
sonson0910
force-pushed
the
fix/const-init-nil-f32-f64-paren-composite-and-str-alias
branch
from
October 18, 2026 15:19
2421c5e to
74cfdad
Compare
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>
…aliases in const_init.rs
sonson0910
force-pushed
the
fix/const-init-nil-f32-f64-paren-composite-and-str-alias
branch
from
October 18, 2026 23:25
74cfdad to
0a99a6e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #670
Summary
Fixes 4
HYB-E6003soundness and false-positive bugs incompiler/crates/hy-check/src/const_init.rs:LitKind::Nilinconstinitializers: RejectsExpr::Lit { kind: LitKind::Nil, .. }inexpr_is_constant_innersoconst e error = nilis rejected withHYB-E6003instead of emitting invalid Go (nil is not constant).f32,f64,char): Adds"f32","f64", and"char"tois_conversion_type_namesoconst a = f64(42),const b = f32(1.5), andtype my_char = char; const c = my_char(65)are accepted.constinis_const_string_expr: Checkscdecl.tysoconst s any = "hello"; const n = len(s)is rejected withHYB-E6003.stringtype aliases and shadowing insidelen(...): Resolves type aliases and checks for shadowing inis_const_string_conversion_targetsotype my_str = string; const n = len(my_str("hello"))is accepted whiletype string = int; const n = len(string(65))is rejected withHYB-E6003.Verification
cargo test --workspacepasses with 4 new regression tests incompiler/crates/hy-check/tests/const_init_soundness.rs.