Skip to content

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner September 25, 2025 11:40
@RikkiGibson RikkiGibson self-assigned this Sep 29, 2025
Updated enum syntax to include 'class' or 'struct' keywords and clarified rules for shape enums.

Each case with a parameter list generates a nested record type. `enum class` generates `sealed record class` types; `enum struct` generates `readonly record struct` types. While these are the generated types, the union implementation may optimize internal storage.

TODO: Should the structs be readonly? Seems like that goes against normal structs (including `record struct`). Seems like that could be opt in with `readonly enum struct X`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting question. I want to note that giving out refs to the fields which implement the case payloads can be problematic, especially mutable refs.

If an enum struct member, wants to be mutable, e.g. reassign the whole this to implement StateMachine.Transition(input), mutating the receiver variable, that is probably ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. This def seems like an ldm question. Inline with tuples and record-structs, i'm leanign toward this being mutable. Basically, we could just say that you get records, and the behavior that comes with them. Then if you really awnt readonly, you opt in, just like with record sstructs.

enum class Result<T>
{
Success(T value),
Error(string message);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this mix of commas and semicolons exceptionally unwieldy in Java enums.

Copy link

@KennethHoff KennethHoff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing i didn't fully understand; is that an alternative proposal to unions, or in addition to?

Logically they feel very similar - and thus is an alternative - but the way it's worded at times ("Shape enums inherit all union pattern matching behavior:") seems to imply unions already exist in the spec


Each case with a parameter list generates a nested record type. `enum class` generates `sealed record class` types; `enum struct` generates `readonly record struct` types. While these are the generated types, the union implementation may optimize internal storage.

TODO: Should the structs be readonly? Seems like that goes against normal structs (including `record struct`). Seems like that could be opt in with `readonly enum struct X`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly enum ref struct?

@CyrusNajmabadi
Copy link
Member Author

or in addition to?

In addition to. As the spec states, these can just compile down to unions.

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.

6 participants