#1647
Clarification / RFC: BigInt(Uint8Array) lowering parity and documentation of runtime-optional storage rules
Context
Following the investigation in #1644 (Record index-signature read parameter widening) and #1645 (SC2020 diagnostic accuracy), three design and policy questions arose regarding lowering parity and documentation.
Questions for Maintainers
-
Parity for
BigInt(Uint8Array)/BigInt(bytes):- In Node.js,
BigInt(new Uint8Array([1])) === 1nandBigInt(new Uint8Array([])) === 0nvia standard JSToPrimitivestring coercion (multi-element typed arrays throwSyntaxError). - Scriptc currently accepts
{bigint, string, f64, bool, unit}inlowerBigIntConstructorValue, but omitsbytes/Uint8Array. - Is extending
lowerBigIntConstructorValueto supportbytesvia runtime dispatch desirable for Node parity?
- In Node.js,
-
Diagnostic code policy vs message enhancement:
- When an expression inside a type guard cannot be lowered because of runtime-optional storage widening, should this eventually receive a dedicated diagnostic code (requiring a surface manifest regeneration), or is refining the existing SC2020/SC1090 message and
hintenvelope preferred?
- When an expression inside a type guard cannot be lowered because of runtime-optional storage widening, should this eventually receive a dedicated diagnostic code (requiring a surface manifest regeneration), or is refining the existing SC2020/SC1090 message and
-
Documentation of runtime-optional callee promotion:
- When indexed reads widen callee parameters to ensure storage safety across call sites, should this rule be explicitly documented under
docs/content/limitations/ortypes-and-class-definitions/unions.mdxto set expectations for library authors targeting static compilation?
- When indexed reads widen callee parameters to ensure storage safety across call sites, should this rule be explicitly documented under
Thanks for the questions! Answers below.
Yes,
BigInt(Uint8Array)should behave like it does in Node. Node converts the array to a string first, soBigInt(new Uint8Array([1]))is1n, an empty array is0n, and an array with more than one element throws aSyntaxError. We'll add support for it inlowerBigIntConstructorValue.We'd like to keep SC2020 and SC1090 and make their messages and hints more useful, rather than add a new code. #1646 adds the part that's missing today:
--explain-dynamicwill show which runtime-optional storage decision bypassed the narrowing, and where.Yes, we'll document the parameter widening from indexed reads. It'll go on the unions page with an example, and the limitations page will link to it.