You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Rust and JavaScript: an enum value that shifts or negates a sibling member fails to compile (Perm::Write as isize << 1, --1) #396
RustGenerator writes enum members (~L2150–2161 of Coder/Languages/RustGenerator.cs) by replacing each sibling reference through RenameSiblingMembers with {name}::{sibling} as {discriminant}, and adds no parentheses. The same file's WriteWidened (~L1427, L1458–1460) does parenthesise as, because, as its comment says, as binds tighter than any operator around it. The enum path breaks in both directions:
Shift: members Read = 1, Write = 2, All = "(Write << 1) - 1" (the common "all flags" idiom) generate All = (Perm::Write as isize << 1) - 1,
rustc rejects this: "<< is interpreted as a start of generic arguments for isize, not a shift".
Negation:A = 1, B = "-A" generates B = -Perm::A as isize,. Rust parses that as (-Perm::A) as isize, which is E0600, "cannot apply unary operator - to type Perm".
Expected output: (Perm::Write as isize) << 1 and -(Perm::A as isize).
JavaScript
WriteEnumMembers (Coder/Languages/JavaScriptGenerator.cs ~L164–183) remembers each earlier member's value so later members can use it. A value that parses as a long is stored unparenthesised, and that includes negative numbers. So A = -1, B = "-A" generates B: --1,. That is a SyntaxError ("Invalid left-hand side expression in prefix operation"), so the module fails to load.
Suggested fix / acceptance criteria
Rust spells a sibling reference ({name}::{sibling} as {discriminant}).
JavaScript parenthesises a remembered value that is negative. For example, store it bare only when it parses and is non-negative.
Rust and JavaScript compile/load tests cover an enum with All = (Write << 1) - 1 and one with B = -A where A is negative.
Related: #258 (closed) introduced sibling renaming. #388 is the separate E0081 duplicate-discriminant problem.
Priority: Medium. All = (Write << 1) - 1 is a common flags idiom, and the Rust output fails to compile. The JavaScript output fails to load as a module. Both failures are loud.
Area:Languages/RustGenerator.cs (enum members, RenameSiblingMembers) and Languages/JavaScriptGenerator.cs (WriteEnumMembers)
Next step: in Rust, wrap the sibling cast in parentheses. In JavaScript, parenthesise remembered negative values. Add compile/load tests for both shapes.
Activity
matt-edmondson commentedon Oct 30, 2026
Triage
All = (Write << 1) - 1is a common flags idiom, and the Rust output fails to compile. The JavaScript output fails to load as a module. Both failures are loud.Languages/RustGenerator.cs(enum members,RenameSiblingMembers) andLanguages/JavaScriptGenerator.cs(WriteEnumMembers)Default = Low, or any repeated value) fails to compile with E0081 "discriminant value assigned more than once" #388 (E0081 duplicate discriminants) is separate. Watch for conflicts: open PR Spell a Python enum value that names an escaped sibling by its escaped name [patch] #380, which spells Python enum values that name escaped siblings, also editsRenameSiblingMembers, and open PR Escape keyword-named enum members in C++ and Rust [patch] #365 escapes keyword-named enum members in Rust. Neither fixes the parenthesisation, but this fix should land after them or be rebased onto them.Generated by Claude Code