fix(parse): split a bare alias at a top-level space - #341
Merged
Conversation
Query<DB, 'select power(age, 2) from users'> // was { '2)': unknown }[]
StrictRow<DB, 'select power(age, 2) from users'> // was unknown column: power(age,
The bare-alias fallback matched `${infer Expression} ${infer Alias}`, which
splits at the first space in the entry with nothing checking whether that
space is inside a call. An unaliased call carrying one in its arguments was
cut in half: the tail became a fake alias and the head a fake column name.
`cast(id as text)`, `extract(epoch from created_at)` and
`coalesce(name, 'anon')` all failed the same way.
The split is now depth-tracked, using the same ApplyParenDelta the sibling
scans already use, so a space inside a call is not a boundary and an entry
that is one call from end to end simply has no alias. An alias written after
the call still is one, with or without AS.
Costs nothing: 191,482 instantiations against master's 192,486. The naive
match was building an alias candidate for entries that then discarded it.
Fixes #276
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/276-multiarg-call-alias
branch
from
August 2, 2026 13:04
51583aa to
5932912
Compare
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.
Fixes #276.
The bug
Adding an explicit alias made it work, but
select power(age, 2)is everyday SQL and should give apowercolumn like other unaliased calls do.The fix
The bare-alias fallback matched
`${infer Expression} ${infer Alias}`, which splits at the first space with no paren-balance check guarding the branch.The split is now depth-tracked, reusing the
ApplyParenDeltathe sibling scans (FindTopLevelAsKeyword,ColumnsBeforeFrom) already use. A space inside a call is no longer a boundary, so an entry that is one call from end to end has no alias to find and falls through toOutputName— which is howcount(*)has always been named.Verification
tests/multiarg-call-alias.test-d.ts, eleven cases. Six red on master:power(age, 2)in both modes,cast(id as text),extract(epoch from created_at),coalesce(name, 'anon'), and one among ordinary columnsASControls:
lower(name),count(*)and a plain bare alias are unchanged.tsc --noEmitclean, 192 runtime tests pass. Budget 191,482 — 1,004 below master: the naive match was building an alias candidate for entries that went on to discard it.