GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: deduplicate enum constant names that collapse to the same identifier by alliasgher · Pull Request #4519 · sqlc-dev/sqlc

Conversation

@alliasgher

@alliasgher alliasgher commented Jul 19, 2026

Copy link
Copy Markdown

What

buildEnums deduplicated enum constant names on EnumReplace(v), but the name actually emitted is StructName(enumName + "_" + value), which collapses characters further (non-idents to _, then _-split + title-case with no separator). So values that produce distinct EnumReplace outputs can still land on the same final identifier.

For a PostgreSQL enum like blood groups:

CREATE TYPE blood_group_type AS ENUM ('A+','A-','B+','B-','AB+','AB-','O+','O-');

"A+" → EnumReplace "A" and "A-" → "A_" are different (so the old dedup didn't fire), but StructName maps both to BloodGroupTypeA. The result was duplicate Go constants that fail to compile.

Fix

Dedup on the final constant name (the StructName output) rather than the intermediate EnumReplace value, keeping the existing value_<i> fallback on collision. Non-colliding enums are unaffected (identical output, no golden changes).

Fixes #4515

Testing

Added TestBuildEnums_DeduplicatesConstantNames. It fails on main with duplicate constant name "BloodGroupTypeA" for values "A+" and "A-" (and B/AB/O), and passes with the fix.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@alliasgher
fix: deduplicate enum constant names that collapse to the same identi…
543ee6d
…fier

buildEnums deduplicated on EnumReplace(v), but the final constant name is
StructName(enumName+"_"+value), which collapses characters further (e.g. a
trailing underscore). So enum values like "A+" and "A-" reduced to distinct
EnumReplace outputs ("A" and "A_") that both mapped to the same constant
name, producing duplicate Go constants that fail to compile. Dedup on the final
constant name instead, falling back to value_<i> on collision.

Fixes sqlc-dev#4515
@alliasgher alliasgher mentioned this pull request Jul 19, 2026
Go code generation fails for PostgreSQL ENUM values with '+' and '-' due to duplicate constant names #4515
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Go code generation fails for PostgreSQL ENUM values with '+' and '-' due to duplicate constant names

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@alliasgher
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.