Skip to content

fix(check): preserve channel direction on struct field fn calls (closes #1358) - #2136

Open
dextermos-dev wants to merge 1 commit into
limitlessprojects:mainfrom
dextermos-dev:fix/1358-channel-direction-fn-struct-field
Open

dextermos-dev wants to merge 1 commit into
limitlessprojects:mainfrom
dextermos-dev:fix/1358-channel-direction-fn-struct-field

Conversation

@dextermos-dev

Copy link
Copy Markdown

Summary

Closes #1358.

This pull request resolves a channel direction tracking defect in hy-check where calling a multi-return function stored in a struct field (_, rx := h.f() where f has type fn() int <-chan int) dropped channel direction constraints, allowing illegal operations like close(rx) on a receive-only channel (<-chan T) to bypass hyb check and fail during go build with cannot close receive-only channel rx.

Root Cause & Changes

  1. Checker::dir_multi_ty_of_call (sendability.rs):

    • In Expr::Field { base, name, .. }, previously only checked self.method_decls and returned early if no method was found.
    • Added fallback to self.struct_fields_for_type(&base_ty). When the field resolves to TypeExpr::Fn { results, .. }, its results vector is returned so channel directions (<-chan T, chan<- T) are tracked in ChanDirEnv.
  2. Checker::call_result_tys (shape.rs):

    • In Expr::Field { base, name, .. }, falls back to self.struct_fields_for_type(&base_ty) to resolve results of fn-typed struct fields.
    • In the wildcard other arm, falls back to self.ty_of_expr(st, other) to resolve result types of direct fn-typed expressions.

Verification

  • Added dedicated test suite in compiler/crates/hy-check/tests/chan_dir_fn_struct_field_1358.rs:
    • rejects_closing_recv_only_channel_from_struct_field_fn_call_issue_1358 (verifies HYB-E3009)
    • rejects_sending_to_recv_only_channel_from_struct_field_fn_call_issue_1358 (verifies HYB-E3008)
    • rejects_receiving_from_send_only_channel_from_struct_field_fn_call_issue_1358 (verifies HYB-E3008)
    • accepts_valid_channel_directions_from_struct_field_fn_call_issue_1358 (verifies valid send/recv/close operations pass)
  • Verified all 4 tests pass (4 passed, 0 failed).
  • Verified cargo test -p hy-check sendability passes.
  • Verified tools/check_conflict_markers.py and tools/check_corpus_census.py pass clean (127/127 programs).

Settlement Wallet: 0x8366bCe3a2D379Dec7656D7A67015789FaF999f20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[soundness] hy-check: multi-return call through fn-typed struct field drops channel direction and lets close(rx) on <-chan T pass hyb check

1 participant