Skip to content

fix(hy-check): reject typed int variables in float var declarations and mismatched copy slice elements (fixes #2560) - #2589

Open
Dimank92 wants to merge 1 commit into
limitlessprojects:mainfrom
Dimank92:fix/issue-2560-float-var-decl-and-copy-slice-soundness
Open

Dimank92 wants to merge 1 commit into
limitlessprojects:mainfrom
Dimank92:fix/issue-2560-float-var-decl-and-copy-slice-soundness

Conversation

@Dimank92

@Dimank92 Dimank92 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #2560, fixes #2538.

This PR addresses soundness issues in hy-check where typed int variables bypassed type checking when initializing float64 variable declarations, and where built-in copy(dst, src) erroneously accepted slice arguments with mismatched element types (e.g. []float64 and []int).

Soundness Analysis & Defect Resolution

  1. Typed Variable Initialization (var / let):

    • In Collector::local, kinds_conflict(&want, &vk) previously allowed typed integer variables to initialize float64 variables because kinds_conflict(Float, Int) returns false to permit untyped constants.
    • We check int_float_conflict = want == OpKind::Float && vk == OpKind::Int && !self.is_untyped_int_const(expr).
    • Initializing a float64 variable with a typed int variable (var i int = 1; var f float64 = i) is now strictly rejected with HYB-E1002.
  2. Built-in copy(dst, src) Slices Element Type Matching:

    • In check_builtin_operand_kinds under "copy", kinds_conflict(dst_elem, src_elem) previously permitted copying between []float64 and []int.
    • We enforce strict element type equivalence for slices: dst_elem == src_elem (unless either is OpKind::Unknown), rejecting mismatched slice copies with HYB-E1002.
  3. Untyped vs Typed Constants:

    • Untyped integer constants (1, const k = 1; var f float64 = k, k + 1) remain legal and accepted per the Go specification.
    • By tracking is_untyped on Define and file_untyped_consts on Collector, typed constants (const k int = 1; var f float64 = k) are properly rejected with HYB-E1002.

Verification

  • Added test suite in compiler/crates/hy-check/tests/var_init_and_copy_slice_soundness.rs:
    • single_var_init_typed_int_to_float_is_rejected
    • let_init_typed_int_to_float_is_rejected
    • copy_slice_mismatched_float_and_int_is_rejected
    • untyped_int_constants_in_float_var_init_accepted
    • typed_int_constants_in_float_var_init_rejected
  • Full test suite passing (178/178 unit tests green).

@github-actions github-actions Bot added bot:stale-base Shepherd: behind main beyond threshold bot:conflict Shepherd: merge conflicts vs main labels Oct 31, 2026
@Dimank92
Dimank92 force-pushed the fix/issue-2560-float-var-decl-and-copy-slice-soundness branch from 73a90b2 to 1604052 Compare November 1, 2026 14:31
@Dimank92

Dimank92 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Rebased cleanly onto current main (commit d2917dcb):

Bounty claim:
/claim #2560
@algora-pbc /claim #2560
Settlement wallet: 0xC345C07229307d4f1c7935aD2cAe48e390215808

@Dimank92
Dimank92 force-pushed the fix/issue-2560-float-var-decl-and-copy-slice-soundness branch from 1604052 to f3546b1 Compare November 1, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:conflict Shepherd: merge conflicts vs main bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

1 participant