Skip to content

codegen/golang: emit any instead of interface{} - #4574

Merged
kyleconroy merged 1 commit into
mainfrom
claude/generated-code-go-fix-etrahi
Aug 20, 2026
Merged

codegen/golang: emit any instead of interface{}#4574
kyleconroy merged 1 commit into
mainfrom
claude/generated-code-go-fix-etrahi

Conversation

@kyleconroy

Copy link
Copy Markdown
Collaborator

Fixes #4470

Generated Go code now uses the predeclared any alias everywhere the generator previously wrote interface{}, so go fix has nothing left to change in sqlc's output.

Generator changes

  • All four Go type mappers (postgresql_type.go, mysql_type.go, sqlite_type.go, go_type.go) return "any" for unknown/fallback types, and the stdlib/pgx templates (DBTX interfaces, exec/query/queryRow helpers, queryParams, batch/copyfrom value slices, enum Scan methods) spell the type any.
  • The unknown-type backfill in result.go matches the new "any" spelling.
  • any is added to the reserved identifier list, and query constant names are now escaped. This fixes a bug the switch would otherwise introduce: a query named Any generated const any = ..., which shadows the predeclared any type package-wide and no longer compiles once the surrounding code uses any. It now generates const any_ (the same _-suffix treatment other reserved identifiers get, which also covers previously-broken constants like const select).

Regenerated output

  • All affected internal/endtoend/testdata golden directories (889 cases), with managed-db-only cases regenerated against a live PostgreSQL through the same config mutation TestReplay applies.
  • All examples/.
  • The six fixture files generation never overwrites (diff_output, diff_no_output, and expected-failure cases), plus the generated-code samples in docs/howto/.

Verification

  • go fix itself skips files with a // Code generated ... DO NOT EDIT. header, so as proof both trees were copied with the markers stripped and run through go fix -diff on Go 1.26: zero diagnostics across all of internal/endtoend/testdata and examples, for every registered fixer (not just the any modernizer).
  • Every golden-file change was verified to be purely the interface{}any rewrite (no unrelated churn); the any case's const any_ rename is the one intentional exception.
  • cd internal/endtoend/testdata && go build ./... passes, and the full suite go test --tags=examples -timeout 20m ./... passes against live PostgreSQL and MySQL, including TestReplay in both the base and managed-db contexts.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Pq9Cgx285AU4NZpCYgtkYS


Generated by Claude Code

Generated Go code now uses the predeclared any alias everywhere the
generator previously wrote interface{}, so running go fix over generated
packages produces no changes (#4470).

- Replace interface{} with any in the Go type mappers (postgresql,
  mysql, sqlite, unknown-engine fallback), the stdlib and pgx templates,
  and the enum Scan methods.
- Reserve the identifier any and escape query constant names: a query
  named Any used to generate 'const any = ...', which shadows the
  predeclared any type package-wide and now would break compilation; it
  generates 'const any_ = ...' instead.
- Regenerate all endtoend golden files and examples, update the diff and
  expected-failure fixtures that generation does not overwrite, and
  update the generated-code samples in docs/howto.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Pq9Cgx285AU4NZpCYgtkYS
@kyleconroy
kyleconroy merged commit dfb6bda into main Aug 20, 2026
13 checks passed
@kyleconroy
kyleconroy deleted the claude/generated-code-go-fix-etrahi branch August 20, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants