Skip to content

fix(hy-check): reject container element, key, value, base, and array alias mismatches in var and let declarations (fixes #3448) - #3468

Open
seenorht wants to merge 1 commit into
limitlessprojects:mainfrom
seenorht:fix/issue-3448-var-decl-container-soundness
Open

seenorht wants to merge 1 commit into
limitlessprojects:mainfrom
seenorht:fix/issue-3448-var-decl-container-soundness

Conversation

@seenorht

@seenorht seenorht commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

Fixes #3448.

1. Summary

Under Go specification (§Variable declarations, §Assignability) and Go-Hybrid's Row 13 (BUILDABLE) soundness guarantee:

  • A typed variable declaration (var or let) requires that initialized expressions match the declared type.
  • Channels must have matching element types; maps must have matching key/value types; slices must have matching element types; pointers must have matching base types; and array aliases must have matching dimensions.
  • In Go:
    • var c chan int32 = ch64 (where ch64 chan int64) -> cannot use ch64 (variable of type chan int64) as chan int32 value in variable declaration
    • var m map[string]int32 = m64 (where m64 map[string]int64) -> cannot use m64 as map[string]int32
    • var s []int32 = s64 (where s64 []int64) -> cannot use s64 as []int32
    • var p *int32 = p64 (where p64 *int64) -> cannot use p64 as *int32
    • var a arr32 = a64 (where type arr32 = [32]byte, type arr64 = [64]byte) -> cannot use a64 as arr32

Prior to this fix, kinds_conflict collapsed these types into coarse kinds (Chan(Int), Map(Str, Int), Slice(Int), Pointer(Int)), while scalar_of_ty and sized_array_names_differ only checked bare scalars and syntactic sized arrays ([3]int), letting mismatched container and alias declarations pass hyb check with 0 diagnostics and fail go build.

2. Surgical Fix

In compiler/crates/hy-check/src/buildable.rs:

  • Implemented resolve_type_str: iteratively unfolds type aliases up to 10 depths using self.ck.type_aliases.
  • Implemented container_type_names_conflict: strictly detects element/key/value/base mismatches across channels (chan, chan<-, <-chan), maps, slices, pointers, and array aliases without disturbing array composite literals or [...]T inferences.
  • Integrated into fn local for both single and multi-variable declarations (var and let), emitting HYB-E1002.

3. Test Coverage

  • Added dedicated regression suite compiler/crates/hy-check/tests/issue_3448_var_decl_container_soundness.rs:
    • test_var_decl_chan_element_mismatch: rejects var c chan int32 = ch64 with HYB-E1002.
    • test_var_decl_map_value_mismatch: rejects var m map[string]int32 = m64 with HYB-E1002.
    • test_var_decl_map_key_mismatch: rejects var m map[int32]string = m64 with HYB-E1002.
    • test_var_decl_slice_element_mismatch: rejects var s []int32 = s64 with HYB-E1002.
    • test_var_decl_pointer_base_mismatch: rejects var p *int32 = p64 with HYB-E1002.
    • test_var_decl_array_alias_mismatch: rejects var a arr32 = a64 with HYB-E1002.
    • test_let_decl_container_mismatches: rejects let container mismatches.
    • test_var_decl_containers_valid_controls: verifies valid channels, maps, slices, pointers, and array aliases accept cleanly.
  • Preserves full compatibility with all existing tests (including array composite literals [3]string{"a"} and [...]string{"a"}).
  • Invariant gates passed:
    • tools/check_guarantees.py: OK.
    • tools/check_test_registration.py: OK.
    • tools/check_conflict_markers.py: OK.

Bounty payout rail: USDC on Base
Recipient settlement: Registered under contributor @seenorht (per BOUNTY.md and Discussion #295)

@seenorht

seenorht commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Settlement wallet (Base USDC): 0x2fbD90378ACb304b4c474B433bf1Ea041EcB4290

@seenorht
seenorht force-pushed the fix/issue-3448-var-decl-container-soundness branch 28 times, most recently from 8e4156f to 53dd1a8 Compare November 4, 2026 18:25
@seenorht
seenorht force-pushed the fix/issue-3448-var-decl-container-soundness branch 29 times, most recently from 70ddd36 to 7ff945e Compare November 6, 2026 21:17
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