Skip to content

hy-check: shape.rs misses generic struct zero-value substitution (HYB-E4002), pointer-to-array index/slice shapes, and struct-field/indexed fn call return shapes (HYB-E3003) #2966

Open

Description

@ket4min-susan

Summary

Auditing compiler/crates/hy-check/src/shape.rs uncovered three soundness bugs in shape and type resolution:

  1. HYB-E4002 (N3 no-zero-value) bypassed on generic struct instantiations (no_zero_value_reason):

    • no_zero_value_reason looks up uninstantiated struct fields via self.structs.get(base) instead of self.struct_fields_for_sname(name).
    • When a generic struct (struct holder[t any] { v t }) is instantiated with a no-zero-value enum (enum tok { item(int) empty }), self.structs.get("holder") inspects the raw type parameter t rather than tok, allowing var h holder[tok] and var o outer[holder[[2]tok]] to bypass HYB-E4002.
  2. Pointer-to-array (*[N]T) indexing (p[i]) and slicing (p[:]) degrade to TypeShape::Unknown (shape_of_expr & ty_of_expr):

    • In Go (and iterate_var_shapes), *[N]T is directly indexable and sliceable without explicit dereference.
    • However, shape_of_expr and ty_of_expr on Expr::Index and Expr::Slice only match TypeShape::Array(e) / TypeExpr::Array, degrading p[0] and p[:] on p := &arr to TypeShape::Unknown / None.
    • Consequently, arr := [1]map[string]int{m}; p := &arr; x := p[0]; alias := x; task worker(move x, done); alias["k"] = 2 records no may_share alias edge (shape_may_share(&Unknown) == false) and bypasses HYB-E3003, while primitive element reads (arr := [2]int{10, 20}; p := &arr; x := p[0]; task worker(x, done)) are falsely rejected with HYB-E3005.
  3. Calls to struct function fields (s.make_map(), s.make_pair()), type-aliased function bindings (f()), and indexed/folded function containers (fns[idx](), b.fns[idx]()) lose return shapes (call_shape, call_result_shapes, ty_of_expr):

    • call_shape checks b.ty for TypeExpr::Fn without resolve_type_alias, and neither call_shape nor call_result_shapes falls back to self.ty_of_expr(st, callee) for struct fields of function type or indexed function containers (including bracketed indices folded into Expr::Ident / Expr::Field by fold_type_args).
    • As a result, m := s.make_map(), m, n := s.make_pair(), m := f(), and m := fns[idx]() degrade to TypeShape::Unknown, bypassing HYB-E3003 when m is moved into a spawned task and later mutated through an alias.

Activity

  1. Dimany4 commented on Nov 1, 2026

    @Dimany4
    Contributor

    /claim #2966

    Settlement wallet (Base USDC): 0x5B58b71e14F9856c344f41813fbC9029670A0e26

    Picked up via the project's own repo watcher — a verified fix with regression tests follows; the PR will be linked here.

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