Represent records with the runtime names "0", "1", ... as Record_array
Why
Whether a record is a JavaScript array was rediscovered from its field names only when js_dump printed a record literal. Every other path treated it as an object: a spread over a record with an optional field or 20 fields became an object spread, and {} printed {} (#9196).
The type declaration now decides once: a record whose fields have the runtime names "0", "1", ... in declaration order gets the representation Record_array, and its blocks carry array to js_dump. A spread over such a record copies its fields one by one. Record rest patterns and coercions whose target is an array record are rejected, as an object spread or an object can't produce an array.
modifiedJS record spread
type t = {@as("0") a?: int, @as("1") b: int}let upd = (r: t) => {...r, b: 2}type e = {@as("0") x?: int}let empty: e = {}
js
addedDiagnostic record rest into an array record
type source = {@as("0") s0: int, @as("1") s1: int, @as("2") s2: int}type head = {@as("0") s0: int, @as("1") s1: int}let split = (r: source) => { let {s2, ...head as rest} = r (s2, rest)}
js
let {"2": __rest_field0, ...rest} = r;diagnostic
The rest of a record pattern cannot have a record type represented as an array (fields with the runtime names "0", "1", ...).addedDiagnostic coercion into an array record
type obj = {@as("0") a: int, @as("1") b: int, x: int}type arr = {@as("0") a: int, @as("1") b: int}let toArr = (x: obj) => (x :> arr)
js
function toArr(x) { return x;}
diagnostic
Type obj is not a subtype of arr The record arr is represented as a JavaScript array (its fields have the runtime names "0", "1", ...), but obj is represented as an object, so it cannot be coerced to it.
Review
- Why not keep checking the names in js_dump? Only the literal printer looked at them. A representation is matched exhaustively by every phase that builds or reads a record, so each of them has to say what an array record means, and no path can miss it again.
- Is coercing an array record to an object record still allowed? Yes: an array has its elements as the properties "0", "1", ..., so
{"0", "1", "2"} :> {"1"}stays valid. Only the other direction is rejected.