Skip to content

query: resolve type lifting after OR parsing#1023

Open
keegancsmith wants to merge 1 commit intomainfrom
k/type-query
Open

query: resolve type lifting after OR parsing#1023
keegancsmith wants to merge 1 commit intomainfrom
k/type-query

Conversation

@keegancsmith
Copy link
Member

@keegancsmith keegancsmith commented Mar 20, 2026

This change fixes a parser ordering bug where type: lifting happened before or placeholder resolution. In unparenthesized queries such as type:repo foo or bar, the parser could previously leave internal orOp sentinels inside a Type child instead of producing a valid Or subtree. That also let malformed queries like type:repo or and or type:repo get accepted in parsing even though they should fail early.

The fix resolves operators first for typed scopes and then wraps the resulting expression in Type, preserving existing top-level type lifting semantics while ensuring or is validated and represented correctly. I also added parser regressions that cover the previously broken type + or case and malformed edge cases.

The query syntax docs now explicitly describe type: scope with or to match parser behavior and reduce ambiguity.

The parser used to lift `type:` directives before converting `or` placeholders into real boolean nodes. That let parse-time `orOp` sentinels leak into `Type` children for unparenthesized queries and allowed malformed inputs like `type:repo or` to parse successfully until runtime.

Resolve operator placeholders before wrapping with `Type` so unparenthesized `or` inside a type scope produces a valid `Or` subtree and malformed `or` placement is rejected during parsing. The docs now clarify that `type:` applies to the whole expression in its current scope, including `or` clauses.

Test Plan:
- go test ./query
- go test ./... -short

Amp-Thread-ID: https://ampcode.com/threads/T-019d0be7-4c9d-76fd-b556-103420d14be9
Co-authored-by: Amp <amp@ampcode.com>
@keegancsmith keegancsmith changed the title fix/query: resolve type lifting after OR parsing query: resolve type lifting after OR parsing Mar 20, 2026
@keegancsmith keegancsmith marked this pull request as ready for review March 20, 2026 15:52
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.

1 participant