Skip to content

Soundness: unify_param_with_arg_shape skips compound generic struct type args (box[[]t], box[*t]), bypassing HYB-E3001 and HYB-E3003 #3948

Open

Description

@CrowAleksito

Summary

In Checker::unify_param_with_arg_shape (compiler/crates/hy-check/src/shape.rs:1868-1884), when a generic function parameter is a generic struct instantiated with a compound type argument that mentions a type parameter t (such as b box[[]t], b box[[1]t], b box[*t], b box[option[t]], b box[map[string]t], or b box[inner[t]]), line 1875 checks if tparams.contains(pa.as_str()). Because pa is "[]t" rather than "t", unification is skipped and subst remains empty.

If the file also defines a package-level type or alias named t (e.g., type t = int or struct t { n int }, which is legal in Go because [t any] on fn first_elem[t](b box[[]t]) t shadows the package-level t), shape_of_type_with_subst falls back to named_shape_depth("t") and classifies the return value of first_elem(b) as TypeShape::Primitive (int) instead of TypeShape::Map(...).

This allows:

  1. Passing first_elem(b) directly to task worker(first_elem(b), done) without move (HYB-E3001 bypass).
  2. Storing alias := first_elem(b) without recording a may_share edge, then moving m via task worker(move m, done) while mutating alias["main"] = 2 concurrently (HYB-E3003 bypass).

Minimal Reproducer (repro_compound_generic_unify.hy)

type t = int

struct box[u] {
    val u
}

fn first_elem[t](b box[[]t]) t {
    return b.val[0]
}

fn worker(m map[string]int, done chan int) {
    m["worker"] = 1
    done <- 1
}

fn main() {
    m := map[string]int{"init": 0}
    b := box[[]map[string]int]{val: []map[string]int{m}}
    done := make(chan int, 1)
    task worker(first_elem(b), done)
    m["main"] = 2
    <-done
}
  • Expected: Verdict::Reject with HYB-E3001 (first_elem(b) returns a map[string]int shared with m and is spawned into task worker without move).
  • Actual: Verdict::Accept (0 diagnostics).

Fix

  1. Add recursive type-argument string unification (unify_param_str_with_arg_shape) in compiler/crates/hy-check/src/shape.rs so compound generic type arguments ([]t, [N]t, *t, option[t], map[k]v, nested inner[t]) inside TypeExpr::Named unify t against the corresponding inner TypeShape.
  2. In fn_call_shape_subst, default any remaining unresolved type parameter in tparam_set to TypeShape::Unknown so shape_of_type_with_subst never resolves an active type parameter against a shadowed package-level type of the same name.

Payout Wallet (Base USDC)

  • Base / EVM (USDC): 0x8132B258bC02F98EbcE321EFf18528938fB58940

Activity

  1. CrowAleksito commented on Nov 7, 2026

    @CrowAleksito
    Author

    Fix PR opened by original reporter (@CrowAleksito): #3949 — Official Base USDC wallet: 0x8132B258bC02F98EbcE321EFf18528938fB58940

  2. added 2 commits that reference this issue on Nov 7, 2026
    2b3f6d3
    b682cc5
  3. zongsm-cmyk commented on Nov 7, 2026

    @zongsm-cmyk
    Contributor

    Submitted clean fix with raw string test fixtures in PR #4056 (#4056).

    • Added recursive compound generic parameter unification in shape.rs (unify_param_str_with_arg_shape).
    • Fixed st.closure_scoped_envs dual-write in freeze.rs and model.rs for block-scoped bindings.
    • Fixed test fixture syntax using r#"..."# so cargo test --workspace compiles cleanly without literal token collisions.

    Closes #3947
    Closes #3948

    /claim #3948
    Base (USDC) Payout Address: 0xC10373008eFb38192C87C375ac63aB12E27C684C

  4. added a commit that references this issue on Nov 7, 2026
    af0b7a4
  5. CrowAleksito commented on Nov 7, 2026

    @CrowAleksito
    Author

    Updated original reporter PR #3949 (#3949) per @limitlessprojects review (using raw string literals r#...# in soundness_closure_scoped_moves_and_compound_generic.rs).

  6. added 7 commits that reference this issue on Nov 7, 2026
    09d7c30
    a3b0fed
    116e0ff
    d93b3dc
    2ddedad
    e262ce0
    9275b1d
  7. added 12 commits that reference this issue on Nov 9, 2026
    9703b90
    3da9078
    dfa5e32
    22b27c0
    b53cb57
    4ce0bdf
    db2850d
    d98c97d
    a3d2bda
    2b0bac6
    4d850a2
    70af916
  8. added 2 commits that reference this issue on Nov 19, 2026
    3124b63
    9632b4a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions