You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
-o x.mjs: a Nat leaves through a return type the marshal cannot resolve as a number, not a BigInt #1150
GUIDE.md says a Nat crossing into JS is a BigInt, and the out-marshal does convert
one when the return type is concrete. It does not when the type is one the marshal
cannot resolve (a type family), and by then the value is the runtime's own — a number,
because the in-marshal converted it.
mini.bend
import Base
type S is Data:
SNat{}
def M(s: S) -> Data:
match s:
case SNat{}:
Nat
def nat_of(s: S, n: Nat) -> Maybe<&2, M(s)>:
match s:
case SNat{}:
Some{n}
bend mini.bend -o mini.mjs, then from JS:
nat_of({$: "SNat"}, 7n).value -> 7 (typeof "number"; expected a BigInt)
The emitted wrapper marshals both arguments and nothing else:
Seen in a real program: dec(s: Schema, r: Raw) -> Maybe<&2, Meaning(s)> in a schema
library returns { $: "Some", value: 6 } for a Nat while the declaration it emits for the
same module says bigint — Meaning(s) is a type family, so the result is unmarshalled.
Same shape as #1105 (a value on a path the marshal does not resolve keeps the runtime's
representation), and the value is exact either way (a Nat is at most 2^48-1 < 2^53), so
this is a representation bug rather than a wrong number. It is reachable from any def whose
return type the marshal cannot resolve, and the fix has to be at the boundary: a caller
cannot tell an internal number from a host number.
Checked this reproducer on main 4f99f4c. The current JS boundary contract uses a number for Nat now: concrete(7).value and nat_of({$: "SNat"}, 7).value both return 7 with typeof number. The old 7n input is rejected with “expected a Nat host number”. I couldn't reproduce the Nat representation mismatch with the current documented input type; no compiler changes made.
Activity
tests: the Nat round trip is exact over the host's own number
oxura commentedon Oct 29, 2026
Checked this reproducer on main 4f99f4c. The current JS boundary contract uses a number for Nat now:
concrete(7).valueandnat_of({$: "SNat"}, 7).valueboth return7with typeofnumber. The old7ninput is rejected with “expected a Nat host number”. I couldn't reproduce the Nat representation mismatch with the current documented input type; no compiler changes made.