| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…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
| Back | FazBrowse Home | New Git URL |
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:
"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.