Skip to content

fix!: name each enum case constant for its enum - #236

Open
robfischer1 wants to merge 1 commit into
arcjet:mainfrom
robfischer1:enum-case-constants
Open

robfischer1 wants to merge 1 commit into
arcjet:mainfrom
robfischer1:enum-case-constants

Conversation

@robfischer1

Copy link
Copy Markdown

WIT scopes a case name to its enum, but gravity emitted every case as an unqualified package constant. Two enums sharing a case name, or a case sharing a type's name, failed go vet:

PeerSvid redeclared in this block

Every constant is now named after its enum, as ColorRed, the way the Go standard library writes http.MethodGet.

Breaking: every enum constant is renamed.

Qualifying only the colliding names, as #197 does for types, was rejected. With that rule, adding an enum later would rename another enum's constants.

Tests:

  • imports::tests::test_enum_case_constants_are_named_for_their_enum
  • The enum-collisions example
  • The existing examples' tests, updated to the new names

🤖 Generated with Claude Code

https://claude.ai/code/session_01K99bnsYaj3w4MMWSF5hTMu

WIT scopes a case name to its enum; gravity emitted every case as an
unqualified package constant. Two enums sharing a case name, or a case
sharing a type's name, then redeclared an identifier and the bindings
failed go vet:

    enum_collisions.go:41:2: PeerSvid redeclared in this block

The identity lift had to spell its `via` cases `via-peer-svid`, ... to
dodge `credential-kind`'s `peer-svid`. Every case constant is now the
enum's Go name followed by the case's (ViaPeerSvid,
CredentialKindPeerSvid, ShapePoint beside the record Point), as Go
spells an enumerated constant (http.MethodGet). The enum's qualified
name is already unique (arcjet#197), so its constants are too.

BREAKING: every enum constant is renamed (Red becomes ColorRed). The
upstream examples' tests are updated, and the regressions WIT drops the
comment that called constant qualification out of scope. Qualifying
only colliding names, as arcjet#197 does for types, was rejected: a new enum
would then rename an existing enum's constants.

Tests: imports::tests::test_enum_case_constants_are_named_for_their_enum
(fails without the fix) and the new enum-collisions example
(TestSharedCaseNamesStayDistinct, TestCaseNamedLikeAType; without the
fix go vet fails with the error above).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@robfischer1
robfischer1 requested a review from a team as a code owner October 7, 2026 14:26
@arcjet-review arcjet-review Bot added the needs review Awaiting human review label Oct 7, 2026
@arcjet-review arcjet-review Bot removed the needs review Awaiting human review label Oct 7, 2026
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