Skip to content

Add drift test keeping ASTVisitor and Walk traversals in sync#276

Merged
git-hulk merged 1 commit into
masterfrom
traversal-drift-test
Jun 12, 2026
Merged

Add drift test keeping ASTVisitor and Walk traversals in sync#276
git-hulk merged 1 commit into
masterfrom
traversal-drift-test

Conversation

@git-hulk

Copy link
Copy Markdown
Member

Summary

Accept/ASTVisitor and Walk/WalkFunc are two independent traversal engines that each encode every node's children separately, so they inevitably drift as node types are added. This PR adds a static drift test and fixes the drift it found.

Changes

  • New TestTraversalEnginesCoverSameNodeTypes: parses the package source with go/ast and asserts set-equality between (a) types with an Accept method, (b) parameter types of ASTVisitor's Visit methods, and (c) case *T entries in Walk's type switch. Any future node type added to one engine but not the other fails CI with the exact type names.
  • Fixes the drift it caught: BoolLiteral, CreateNamedCollection, NamedCollectionParam, and WindowFrameParam were missing from Walk's switch — Walk silently skipped their subtrees (e.g. named-collection params and their values were never visited).
  • Fixes a confirmed visitor bug: JoinTableExpr.Accept returned early when SampleRatio != nil, so VisitJoinTableExpr was never called for table expressions with a SAMPLE clause. Added TestVisitJoinTableExprWithSampleRatio as regression coverage.

Testing

Full suite passes including -race -compatible.

🤖 Generated with Claude Code

Accept/ASTVisitor and Walk/WalkFunc are two independent traversal
engines that encode every node's children separately, so a new AST node
type added to one can silently be missing from the other. Add a static
test that parses the package source and asserts every type with an
Accept method has both a Visit method on the ASTVisitor interface and a
case in Walk's type switch, and vice versa.

The test immediately caught four types missing from Walk - BoolLiteral,
CreateNamedCollection, NamedCollectionParam and WindowFrameParam - and
their cases are added.

Also fix a confirmed traversal bug: JoinTableExpr.Accept returned early
after visiting the sample ratio, so VisitJoinTableExpr was never called
for table expressions carrying a SAMPLE clause. Add a regression test.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@git-hulk git-hulk merged commit 558390d into master Jun 12, 2026
4 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.

1 participant