Skip to content

Number Python and JavaScript enum members on from the previous value - #89

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/79-enum-implicit-values
Sep 27, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/79-enum-implicit-values

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #79

What changed

  • Added LanguageGeneratorBase.EnumMemberValues. It gives each member without its own value the previous member's value plus one, the same numbering C, C++, Rust and Go use. When the previous value isn't a plain integer, such as 1 << 4, the next member gets (1 << 4) + 1, then (1 << 4) + 2. Unlike a member name, that expression is valid in both a Python class body and a JS object literal.
  • PythonGenerator.GenerateEnumDeclaration and JavaScriptGenerator.WriteEnumMembers now use it instead of member.Value ?? index.
  • Added tests in TypeDeclarationTests:
    • Red, Green = 5, Blue gives Blue = 6 in Python and JS. Before this change it gave 2.
    • A member after a non-numeric value counts on from that expression.

Verification

  • Without the generator change, both new tests fail. With it, both pass.
  • dotnet build: clean, no analyzer errors. Full suite: 907/907 pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89


Generated by Claude Code

…[patch]

A member with no value of its own took its position, so after an explicit
value the two languages disagreed with C, C++, Rust and Go and could repeat
an earlier value, which Python turns into a silent alias. Fixes #79.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012B4b6sZaZ7tFJzNvax1B89
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit efdf123 into main Sep 27, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/79-enum-implicit-values branch September 27, 2026 00:17
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.

Python and JavaScript enums number members after an explicit value by index, so values diverge from other targets and can collide

2 participants