Skip to content

Let a comment after a string literal keep it a literal in the type checks - #139

Merged
kvlonge merged 2 commits into
mainfrom
fix/d351-comment-literal
Nov 7, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/d351-comment-literal

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Launch blocker D351 (a D327 follow-up from the playground lane): a comment after a string literal changed the playground's Checks outcome.

The bug

On main 9c008e0, with a schema where ORDERS.ORDERED_AT is TIMESTAMP_NTZ, the playground's analyze reported W210 "Incompatible comparison between timestamp and string" for select order_id from orders where ordered_at >= '2026-10-03' -- trailing comment, and for the same query with /* c */. Without the comment, or with a ;, checks pass. Snowflake compiles all four, casting the text implicitly. Translation already passed in all four.

The cause

A comment straight after an expression wraps it in an Annotated node. string_literal in lineage/_helpers/checks/coercion.rs looked through aliases and parentheses but not that wrapper. So '2026-10-03' -- c stopped counting as a string literal, the run-time coercion exemption for Snowflake comparisons didn't apply, and W210 fired. The native CLI looked clean only because sqlquack check takes no schema and can't type ORDERED_AT. The typed checks run only where a schema is supplied, as the playground's analyze(sql, SCHEMA) does.

The fix

string_literal now looks through an Annotated node that only carries comments. A wrapper that asserts a type (type_assertion / type_like) is still not a literal. The same helper also feeds literal_coerces and the signature checks, so they see through the comment too.

Tests

  • test_checks gains one Snowflake row: shipped_at >= '2026-10-03' /* c */ AND shipped_at < '2026-10-04' -- c expects no findings. On main it fails with two W210s, at offsets 35 and 74; with the fix it passes.
  • Sweep (scratch test, not committed): 12 Snowflake queries over the typed shop schema, with /* c */ and -- c inserted after every token, 296 variants in all, comparing finding codes with the uncommented query. On main, 10 of 296 differ, all W210 on a date, time, timestamp or number compared with a commented string literal. With the fix, 0 of 296 differ.

Gate

GATE_RESULTS

Draft, for the auditor. GitHub Actions is blocked by billing; the local D94 gate counts.

…ecks (D351)

A comment straight after an expression wraps it in an Annotated node.
string_literal looked through aliases and parentheses but not that
wrapper, so in WHERE ordered_at >= '2026-10-03' -- c the literal no
longer counted as a string literal, the run-time coercion exemption for
comparisons did not apply, and Snowflake checks reported W210. A
comment-only wrapper is now seen through; one asserting a type is not.
kvlonge added a commit that referenced this pull request Nov 7, 2026
@kvlonge kvlonge changed the title Let a comment after a string literal keep it a literal in the type checks (D351) Let a comment after a string literal keep it a literal in the type checks Nov 7, 2026

kvlonge commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Gate on exact head 139fc9e (44e662c plus a clean merge of main 1362af4, no conflicts), every .rs touched before the build:

  • make check-merge (check-ci + test-rust): exit 0. fmt, clippy, ruff, ty and fensu clean; 24/24 test binaries passed.
  • sqlquack verify --require-verified --strict-errors --python .venv/bin/python: 12,033 cases, 7,997 passed, 1,035 diverged as expected, 2,964 refused, 37 typed, 0 pending, 0 unproven, 0 failed; 226 of 226 equivalences and rules verified.
  • syntax-coverage results … --against main 1362af4's results-baseline.json: 0 regressions, 0 other changes; no baseline re-record needed.
  • Hygiene scan clean; no agent trailers. Audit record 74263da.

@kvlonge
kvlonge marked this pull request as ready for review November 7, 2026 06:32
@kvlonge
kvlonge merged commit 139fc9e into main Nov 7, 2026
1 of 2 checks passed
@kvlonge
kvlonge deleted the fix/d351-comment-literal branch November 7, 2026 07:42
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