Repository navigation
fix(check): preserve channel direction on struct field fn calls (closes #1358) - #2136
Open
dextermos-dev wants to merge 1 commit into
Open
dextermos-dev wants to merge 1 commit into
dextermos-dev wants to merge 1 commit into
Conversation
This was referenced Oct 30, 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
Closes #1358.
This pull request resolves a channel direction tracking defect in
hy-checkwhere calling a multi-return function stored in a struct field (_, rx := h.f()wherefhas typefn() int <-chan int) dropped channel direction constraints, allowing illegal operations likeclose(rx)on a receive-only channel (<-chan T) to bypasshyb checkand fail duringgo buildwithcannot close receive-only channel rx.Root Cause & Changes
Checker::dir_multi_ty_of_call(sendability.rs):Expr::Field { base, name, .. }, previously only checkedself.method_declsand returned early if no method was found.self.struct_fields_for_type(&base_ty). When the field resolves toTypeExpr::Fn { results, .. }, its results vector is returned so channel directions (<-chan T,chan<- T) are tracked inChanDirEnv.Checker::call_result_tys(shape.rs):Expr::Field { base, name, .. }, falls back toself.struct_fields_for_type(&base_ty)to resolveresultsoffn-typed struct fields.otherarm, falls back toself.ty_of_expr(st, other)to resolve result types of directfn-typed expressions.Verification
compiler/crates/hy-check/tests/chan_dir_fn_struct_field_1358.rs:rejects_closing_recv_only_channel_from_struct_field_fn_call_issue_1358(verifiesHYB-E3009)rejects_sending_to_recv_only_channel_from_struct_field_fn_call_issue_1358(verifiesHYB-E3008)rejects_receiving_from_send_only_channel_from_struct_field_fn_call_issue_1358(verifiesHYB-E3008)accepts_valid_channel_directions_from_struct_field_fn_call_issue_1358(verifies valid send/recv/close operations pass)4 passed, 0 failed).cargo test -p hy-check sendabilitypasses.tools/check_conflict_markers.pyandtools/check_corpus_census.pypass clean (127/127 programs).Settlement Wallet:
0x8366bCe3a2D379Dec7656D7A67015789FaF999f20