-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expanded enums and unions #9712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
This document introduces the concepts of enums and unions, detailing their syntax, semantics, and expansion options. It provides examples and grammar definitions for both types.
meetings/working-groups/discriminated-unions/enums-and-unions.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Joseph Musser <[email protected]>
Enum declaration: | ||
|
||
```C# | ||
enum JsonValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i like the practical example.
## Syntax | ||
|
||
Expanded enum: | ||
```bnf |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my pref is we stick with g4. IT's how we do all our grammars :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot rewrite to g4 syntax
meetings/working-groups/discriminated-unions/enums-and-unions.md
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This proposal introduces a new discriminated union syntax for C# by separating enum
and union
into distinct type declarations. It outlines expanded enums as algebraic data types and unions as simple type unions.
- Defines syntax and semantics for both
enum
andunion
type declarations - Provides grammar specifications in BNF notation for both constructs
- Explores expansion options including partial declarations and record bodies
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
<field-list> ::= <field> { "," <field> } | ||
<field> ::= <type> <field-name> | ||
<type> ::= <simple-type> | <generic-type> | ||
<simple-type> ::= "double" | "bool" | "string" | <type-name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The enum grammar defines <simple-type>
without including 'int', but the union grammar on line 56 includes 'int'. For consistency, both grammars should include the same basic types or the difference should be explained.
<simple-type> ::= "double" | "bool" | "string" | <type-name> | |
<simple-type> ::= "double" | "bool" | "string" | "int" | <type-name> |
Copilot uses AI. Check for mistakes.
String, | ||
Object, | ||
Array, | ||
Null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The semicolon after 'Null' is inconsistent with the proposed enum syntax shown earlier in the document where variants are separated by commas. This example should use consistent syntax.
Null; | |
Null, |
Copilot uses AI. Check for mistakes.
This document introduces the concepts of enums and unions, detailing their syntax, semantics, and expansion options. It provides examples and grammar definitions for both types.