Repository navigation
Bake mixed-scalar JSON tables and destructure unions of arrays and tuples - #1455
Merged
Merged
Conversation
JSON documents whose rows mix strings and numbers (`(string | number)[][]`, `(string | number[])[][]`, the character-set and code-point tables of iconv-lite and tr46) now bake: comptime literals take union-typed elements and pick each value's arm from its JSON kind and contents. Array destructuring of a union of array and tuple types (`const [m, a, b] = re.exec(s) || ["", "", ""]`) reads each position from the arm the value holds: a tuple arm answers its field or undefined past its end, an array arm its element or undefined past its end. Unions of tuple types no longer pick the checker's `length` literal as a discriminant: tuple shapes have no such slot. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
`const [hit] = re.exec(s) || ""` destructures `RegExpExecArray | string`: the string arm answers its code point at each position, or undefined past its end, as the string iterator does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…bake A null-valued JSON field bakes as null, so the fixture's document now compiles. It keeps its purpose with a value no literal spells (1e400 parses to Infinity), and the mixed-table corpus program covers null elements. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A comptime record value whose union has a discriminant takes the arm its discriminant field names, so a value that fits two arms with overlapping shapes gets that arm's tag and layout instead of the first arm it fits. comptimeBakeable reports a record type reachable from its own fields as not bakeable instead of recursing without end, so such a comptime result reports SC1090, and the message names unions and that limit.
The bakeability check tracks the unions it is inside as well as the records, so a union reachable from itself through an array (`type Tree = number | Tree[]`) reports SC1090 instead of recursing without end. The message names both recursive records and recursive unions.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two shapes that keep common npm packages and service code from compiling.
JSON tables whose rows mix strings and numbers
JSON documents a CommonJS package requires, and JSON modules a TypeScript file imports, bake into the binary as literals. The baker accepted numbers, strings, booleans, arrays and records, but not unions, so rows typed
(string | number)[]or(string | number[])[]were refused, with a misleading "elements have no array representation" message. iconv-lite's encoding tables and tr46's mapping table have exactly this shape.Literals now bake union-typed elements: each JSON value takes the first arm of the union it fits, by its JSON kind and, for arrays and records, its contents (records are exact, as before).
nullvalues and null-valued fields bake as null.Array destructuring of unions of arrays and tuples
re.exec(s) || ["", "", ""]has the typeRegExpExecArray | [string, string, string], a union of an array and a tuple, which array destructuring refused (only unions of arrays compiled). Each position now reads the arm the value holds: a tuple arm answers its field, or undefined past its end; an array arm its element, or undefined past its end. A string arm (re.exec(s) || "") answers its code point at the position, as the string iterator does. Defaults fire exactly where JavaScript's do. Rest elements over such unions stay refused.Tuple unions and discriminants
A union of tuple types (
[string, boolean] | [string, boolean, number]) picked the checker'slengthliteral as its discriminant, but tuple shapes keep only their positions, so the validator rejected the union with an internal error once a program materialized it (which the destructuring above now does). Tuple unions no longer get a discriminant.Evidence
6410-json-mixed-scalar-tables(two packages modeled on a character-set table and a code-point range map, required at load and inside a function, plus an ES module JSON import) and6411-union-array-tuple-destructuring.ts. Both match Node byte for byte in the plain and sanitized lanes.json-shapefixture's document compiled once its null field baked, so it now uses a value no literal can spell (1e400, which parses to Infinity) and still reports at the import.diagnostics.test.ts: 199/199.pnpm lintandpnpm format:checkare clean, andpnpm test:ts7 --baselines-onlypasses, with 2 new baselines and no existing ones changed.🤖 Generated with Claude Code