Skip to content

Browser State<T> default mis-seeds a composite-Float type arg as float 0.0 via key.includes('Float') substring match #920

Description

@aallan

Summary

In vera/browser/runtime.mjs, the State<T> host bindings (~lines 1347-1383) pick the initial state-cell default with key.includes('Float') ? 0.0 : BigInt(0), where key is the mangled type-arg suffix captured from the import name (state_get_<suffix>). After #914, composite State type arguments compile — e.g. State<Tuple<Float64, Int>> mangles to state_get_Tuple_LFloat64_C_Int_R. Such a composite/ADT state is represented as an i32 heap pointer, so its default cell value must be BigInt(0) (integer 0 / null pointer), not 0.0. But key.includes('Float') matches the substring "Float64" inside the mangled composite name and wrongly seeds the cell with the JS float 0.0.

Scope / reachability

Fix direction

Base the browser default on the actual WASM value type of the import, not a substring match on the mangled name:

  • (a) read the scalar-vs-pointer (f64 vs i32/i64) distinction from the import's declared param/result type via WebAssembly.Module.imports metadata if available, or
  • (b) tighten the heuristic so ONLY a bare primitive Float64 suffix (exact match, not a substring inside a composite name) is treated as float; any composite/ADT suffix takes the integer/pointer default.

Add a Node-vs-Python browser parity test in tests/test_browser.py for a State<Tuple<Float64, Int>> (or State<Option<Float64>>) read-before-put program; mutation-validate. Update doc counts + regenerate site assets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions