codegen/golang: emit any instead of interface{} - #4574
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4470
Generated Go code now uses the predeclared
anyalias everywhere the generator previously wroteinterface{}, sogo fixhas nothing left to change in sqlc's output.Generator changes
postgresql_type.go,mysql_type.go,sqlite_type.go,go_type.go) return"any"for unknown/fallback types, and the stdlib/pgx templates (DBTXinterfaces,exec/query/queryRowhelpers,queryParams, batch/copyfrom value slices, enumScanmethods) spell the typeany.result.gomatches the new"any"spelling.anyis added to the reserved identifier list, and query constant names are now escaped. This fixes a bug the switch would otherwise introduce: a query namedAnygeneratedconst any = ..., which shadows the predeclaredanytype package-wide and no longer compiles once the surrounding code usesany. It now generatesconst any_(the same_-suffix treatment other reserved identifiers get, which also covers previously-broken constants likeconst select).Regenerated output
internal/endtoend/testdatagolden directories (889 cases), with managed-db-only cases regenerated against a live PostgreSQL through the same config mutationTestReplayapplies.examples/.diff_output,diff_no_output, and expected-failure cases), plus the generated-code samples indocs/howto/.Verification
go fixitself skips files with a// Code generated ... DO NOT EDIT.header, so as proof both trees were copied with the markers stripped and run throughgo fix -diffon Go 1.26: zero diagnostics across all ofinternal/endtoend/testdataandexamples, for every registered fixer (not just theanymodernizer).interface{}→anyrewrite (no unrelated churn); theanycase'sconst any_rename is the one intentional exception.cd internal/endtoend/testdata && go build ./...passes, and the full suitego test --tags=examples -timeout 20m ./...passes against live PostgreSQL and MySQL, includingTestReplayin both the base and managed-db contexts.🤖 Generated with Claude Code
https://claude.ai/code/session_01Pq9Cgx285AU4NZpCYgtkYS
Generated by Claude Code