Repository navigation
fix(hy-check): reject typed int variables in return statements and channel sends for float targets (fixes #2575) - #2587
Open
Dimank92 wants to merge 1 commit into
Conversation
…annel sends for float targets (fixes limitlessprojects#2575)
This was referenced Nov 1, 2026
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.
Summary
Fixes #2575.
This PR addresses soundness issues in
hy-checkwhere typedintvariables bypassed type checking when returned from functions declaringfloat64return types and when sent to channels of typechan float64.Soundness Analysis & Defect Resolution
Return Statements:
report_return_conflict,kinds_conflict(want, got)alone permitsintvalues to be returned forfloat64result types becausekinds_conflict(Float, Int)evaluates tofalse.val: &Exprtoreport_return_conflictand checkint_float_conflict = *want == OpKind::Float && *got == OpKind::Int && !self.is_untyped_int_const(val).intvariable (e.g.var i int = 1; return i) is returned in single or multi-return positions, it is strictly rejected withHYB-E1002.Channel Send Statements:
Stmt::SendandSelectArmKind::Send, sending tochan float64previously omitted primitive element assignability checks, allowing typedintvariables to bypassHYB-E3011.check_chan_send_operand_kinds, rejecting typed integer variables sent tochan float64withHYB-E1002.Untyped vs Typed Constants:
1,const k = 1; return k,ch <- k,k + 1) remain legal and accepted per Go semantics.is_untypedonDefineandfile_untyped_constsonCollector. This ensures typed constants (e.g.const k int = 1; return k/ch <- k) are properly rejected in compliance with the Go language specification.Verification
compiler/crates/hy-check/tests/return_and_send_float_int_soundness.rs:single_return_typed_int_to_float_is_rejectedmulti_return_typed_int_to_float_is_rejectedchannel_send_typed_int_to_float_chan_is_rejectedselect_send_typed_int_to_float_chan_is_rejecteduntyped_int_constants_in_return_and_send_are_acceptedtyped_int_constants_in_return_and_send_are_rejected