Skip to content

fix(parse): recognize a window function using a named window - #342

Merged
tiagolauer merged 1 commit into
masterfrom
fix/301-named-window
Aug 2, 2026
Merged

fix(parse): recognize a window function using a named window#342
tiagolauer merged 1 commit into
masterfrom
fix/301-named-window

Conversation

@tiagolauer

Copy link
Copy Markdown
Owner

Fixes #301.

The bug

Query<DB, 'select sum(salary) over w from users window w as (order by id)'>
// { 'over w': number }[]

Expected { sum: number }[]. The value type comes out right by coincidence; the key is nonsense.

The fix

FindOverKeyword/SplitWindowExpression required a ( directly after over, so the named-window form was not recognized as a window expression and the entry fell through to the first-space bare-alias split — making over w the alias of sum(salary).

What follows OVER may now be a name instead of an inline definition, in which case it is consumed as the window reference and whatever comes after it is treated as the alias, exactly as the parenthesized form already does.

The [never] guard that came with it is the interesting part. FindOverKeyword resolves to never for an entry with no OVER at all, and never extends { expr: infer E extends string; rest: infer R extends string } passes with both infers falling back to their constraints — so with the paren no longer required, Rest came through as string and every column in the suite was read as a window function (308 errors across 42 files on the first run). Same [never] pattern ExtraSourcesAfterKeyword and ParseWithClause already carry.

Verification

tests/window.test-d.ts, three new cases, all red on master:

tests/window.test-d.ts(47,3): error TS2344: Type 'false' does not satisfy the constraint 'true'.
tests/window.test-d.ts(54,3): ...
tests/window.test-d.ts(61,3): ...
  • over w unaliased (keyed sum), with an as total alias, and alongside a regular column

The four existing assertions (inline over (...), empty over (), aliased, alongside a column) stay pinned.

tsc --noEmit clean, 192 runtime tests pass, budget 192,572 (+86).

    Query<DB, 'select sum(salary) over w from users window w as (order by id)'>
    // was { 'over w': number }[]

`over w` refers to a window declared in a WINDOW clause - the other half of
the syntax, where what follows OVER is a name rather than an inline
definition. FindOverKeyword and SplitWindowExpression both wanted a paren
directly after `over`, so the entry was not read as a window expression at
all and fell through to the first-space bare-alias split, which made
`over w` the alias of `sum(salary)`. The value came out right by coincidence;
the key was nonsense.

The [never] guard added alongside it is load-bearing: FindOverKeyword
resolves to never for an entry with no OVER, and `never extends { expr:
infer E extends string; rest: infer R extends string }` passes with both
infers falling back to `string`, which the new named-window branch would
have accepted as a window name - every column in the suite came back a
window function until the guard went in.

Fixes #301

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@tiagolauer
tiagolauer force-pushed the fix/301-named-window branch from bb99099 to 9e5d23c Compare August 2, 2026 13:04
@tiagolauer
tiagolauer merged commit 6335b7f into master Aug 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Named window (over w) produces a nonsense column key

1 participant