Repository navigation
Description
Summary
Exported JavaScript functions reject invalid Nat arguments with a message claiming the value is past 2^48-1, even when the invalid input is negative, fractional, or a BigInt. The same function accepts valid numeric inputs above that stated limit, through 2^53. This report concerns the diagnostic wording; the tested invalid inputs are correctly rejected.
Steps to reproduce
Using either tested build from Runtime or environment, save the following files in the same directory.
The file
interop.bend:
import Base
def ident(n: Nat) -> Nat:
ninterop-test.mjs:
import M from './interop.mjs';
import assert from 'node:assert/strict';
for (const n of [0, 5, 2 ** 48, 2 ** 53]) {
assert.equal(M.ident(n), n);
console.log('accepted', n);
}
for (const [name, n] of [
['bigint', 5n], ['negative', -1], ['fraction', 1.5],
['above-range', 2 ** 53 + 2], ['infinite', Infinity], ['nan', NaN],
]) {
assert.throws(() => M.ident(n), (error) => {
console.log('rejected', name, String(error));
return true;
});
}What you did
For the release executable, run:
bend interop.bend -o interop.mjs
bun interop-test.mjsFor the source checkout, replace the first command with bun /path/to/checkout/bend2/main.ts interop.bend -o interop.mjs and run the same consumer.
Expected behavior
A rejected host Nat argument should receive a diagnostic consistent with the host input contract: a JavaScript number that is a whole number from 0 through 2^53. It should not imply that the supported exported-function input ceiling is 2^48-1 or that every rejected value exceeded an upper bound.
Actual behavior
What happened
Both compilers and both consumer runs exited 0; the consumer catches and asserts each rejection. Both runs printed:
accepted 0
accepted 5
accepted 281474976710656
accepted 9007199254740992
rejected bigint bend: a Nat past the largest immediate 2^48-1
rejected negative bend: a Nat past the largest immediate 2^48-1
rejected fraction bend: a Nat past the largest immediate 2^48-1
rejected above-range bend: a Nat past the largest immediate 2^48-1
rejected infinite bend: a Nat past the largest immediate 2^48-1
rejected nan bend: a Nat past the largest immediate 2^48-1
Evidence
- Expected source: The JS host conversion in
bend2/comp.tsaccepts integer numbers from 0 through2 ** 53;host()routes exported Nat inputs through that function. The JS side guide states the same whole-number range for Nat effect answers. PR #1506 explicitly describes that range for exported Nat arguments too. - Failure source: The inline consumer produced the output above on both tested builds. In the source checkout,
nat_in()delegates every invalid value tonat_chk(Infinity), whose emitted diagnostic uses the immediate-Nat limit. - Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
Restoration check
Run the same consumer. All six invalid inputs must remain rejected, with a diagnostic that describes the JavaScript Nat input contract without the misleading immediate-Nat bound. Keep the valid 2 ** 48 and 2 ** 53 assertions passing so a narrower accepted range cannot mask the wording defect.
Runtime or environment
- Latest published release tested: Bend 2.0.37, tag
v2.0.37, revision4ff8545f19b09b7d2b8ca2303668100eac8efd66, using the official Darwin ARM64 release executable in an isolated installation. - Current default branch tested:
main, at the revision pinned in the source links above, invoked throughbun bend2/main.tsin a fresh checkout. - Version command used:
bend versionprintedbend 2.0.37. uname -sm:Darwin arm64.- JavaScript runtime: Bun 1.4.3 for both source compilation and both emitted-module consumer runs.
- Native compilation was not involved.
Triage assessment
- Impact level: P3
- Assessment status: supported
- Impact basis: The observed defect is misleading error wording for invalid JavaScript Nat arguments; valid boundary values still round-trip and the invalid inputs are rejected.
- Workaround status: available
- Workaround basis: Callers can validate that inputs are JavaScript integer numbers from 0 through 2^53 before calling the exported function; the inline valid controls demonstrate that the documented boundary values work.
Activity