Skip to content

hy-check: preserve the option[T] wrapper through index, deref, receive, select, range, and aliases (fixes #753) - #1788

Open
swappysh wants to merge 1 commit into
limitlessprojects:mainfrom
swappysh:fix/option-shape-erasure-753
Open

swappysh wants to merge 1 commit into
limitlessprojects:mainfrom
swappysh:fix/option-shape-erasure-753

Conversation

@swappysh

Copy link
Copy Markdown

Summary

shape_of_type folded option[T] to its payload, and the expression helpers never re-synthesized the wrapper for an operand that was not a bare identifier. An option[chan int] or option[atomic.int64] reached the send/recv/range and address-of checks as the bare payload, so accepted programs raced with 0 diagnostics.

Fixes #753.

import "sync/atomic"
struct opt_box { v option[int] }

fn worker_ptr(p *option[atomic.int64]) {}
fn worker_box(b opt_box) {}

fn main() {
    xs := []option[chan int]{some(make(chan int, 1))}
    xs[0] <- 1                 // E3007 bypass: `xs[0]` read as bare chan int
    v := <-xs[0]

    var opt option[atomic.int64] = none
    task worker_ptr(&opt)      // E3001 bypass: `&opt` read as *atomic, sendable

    b := opt_box{v: some(1)}
    task worker_box(b)
}

Root cause

hy-check/src/shape.rs:

  • shape_of_type recursively folded option[T] to shape_of_type(T) for pointer, slice, array, map, and chan element positions.
  • expr_is_option did not handle Expr::Index, Expr::Deref, Expr::Field, Expr::Receive, Expr::Paren, Expr::Move, and did not resolve type aliases.
  • ty_of_expr and multi_value_tys did not synthesize a TypeExpr for Expr::Index, Expr::Deref, Expr::Receive, or Expr::Field; SelectRecv and ForKind::Iterate passed None as the binding type; opt = none overwrote a specific wrapper with option[any].

Fix

Preserve the outer option[...] wrapper in shape_of_type, teach expr_is_option / ty_of_expr / multi_value_tys the indexed, dereferenced, field, receive, select and range forms plus aliases, keep the declared wrapper on none reassignment, and thread the wrapper through sendability.rs, recv.rs, range_iter.rs, emit_guard.rs, loans.rs, and closures.rs.

Tests

compiler/crates/hy-check/tests/recv_operand_soundness.rs, 10 regressions, 5 of which fail on the previous main.

Gates

  • cargo test --workspace from compiler, green.
  • corpus harness, 127/127 verdict agreement, tripwire not fired.
  • differential loop, FULL AGREEMENT (41/41 accept build+run, 86/86 reject).

Refs #755 (the same fix, closed by the queue sweeper).

…e, select, range, and aliases (fixes limitlessprojects#753)

`Checker::shape_of_type` folded `option[T]` to `shape_of_type(T)` and the
expression helpers never resynthesized the wrapper for an operand that was
not a bare ident, so an `option[chan int]` or `option[atomic.int64]` reached
the send/recv/range and address-of checks as its bare payload:

- `xs[0] <- 1`, `<-xs[0]`, `for v in xs[0]`, `m["k"]`, `*p`, `h.opt`, a
  channel receive, a select receive arm, and a type alias were all treated as
  the payload type, so `HYB-E3007` (send/recv) and `HYB-E2008` (range) were
  skipped.
- The payload being sendable made `&xs[0]`, `&h.opt`, `p`, and a struct with
  an `option[...]` field read as sendable, skipping `HYB-E3001` / `E3103` /
  `E3104` across a task boundary.

`expr_is_option`, `ty_of_expr`, and `multi_value_tys` now recognize `Index`,
`Deref`, `Field`, `Receive`, `SelectRecv`, `ForKind::Iterate`, and aliases,
and reassigning `none` keeps the declared wrapper. `shape_of_type` keeps the
outer wrapper for pointer and container element positions instead of
collapsing it.

Tests: 10 regressions in
`compiler/crates/hy-check/tests/recv_operand_soundness.rs` (5 fail on the
previous `main`).

Gates: cargo test --workspace green; corpus 127/127 (tripwire not fired);
differential FULL AGREEMENT (41/41 accept, 86/86 reject).

Refs limitlessprojects#755 (same fix, closed by the queue sweeper).
@swappysh

Copy link
Copy Markdown
Author

Payout address

EVM (ETH / Base / Arbitrum / Polygon / BSC): 0x44e76Eef9ee687915F5DEd9A6fB66A3C7b774274

USDT-TRC20 (Tron) alternative, same seed, if that rail is preferred: TH1887Tjr372ajGgcxqe7RNmMK4ySSVPCX

@github-actions github-actions Bot added bot:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) bot:stale-base Shepherd: behind main beyond threshold labels Oct 26, 2026
@github-actions github-actions Bot added the bot:conflict Shepherd: merge conflicts vs main label Nov 1, 2026
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:land-candidate Shepherd: fresh, gate-clean, verifiable (set from classify()) bot:stale-base Shepherd: behind main beyond threshold

Projects

None yet

1 participant