Skip to content

Exn<String> handler type tag fails: String maps to i32_pair, not a valid WASM tag parameter #416

@aallan

Description

@aallan

Problem

Exn<String> cannot be used as an exception handler type because String is represented as an i32_pair in the WASM ABI, and WASM exception tags only support scalar types (i32, i64, f64, f32).

-- This fails at compile/run time:
handle[Exn<String>] { ... }

Workarounds:

  • Use Exn<Int> or another scalar-typed exception (consistent with ch07_exn_handler.vera)
  • Or wrap the string in an ADT before throwing

Root Cause

The WASM exception proposal requires tag parameters to be value types. String in Vera is a fat pointer (i32_pair: pointer + length), which cannot be encoded as a single WASM tag parameter.

Fix

Either:

  1. Encode String-typed exceptions as a single heap pointer (i32) in the WASM tag, with the string allocated on the linear memory heap, or
  2. Automatically box i32_pair types when used in exception tags

Impact

Users cannot throw/catch string-valued exceptions, which is a common pattern (error messages). This was discovered while writing tests/conformance/ch07_nested_handlers.vera.

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