allow keywords as values in enums (and tagged unions)
This commit is contained in:
+28
@@ -39,6 +39,34 @@ roadmap and milestone history.
|
||||
- native sum composition with `A | B` for unbacked enums and tagged unions, using program-global `u16` variant ids
|
||||
- fallible channel types `T ! E`, where `E` is a native enum/tagged union or supported sum composition
|
||||
|
||||
#### keyword member names
|
||||
|
||||
Reserved keywords are valid native enum members and tagged-union variants when used in an
|
||||
unambiguous member context:
|
||||
|
||||
```bro
|
||||
TokenKind :: enum {
|
||||
if
|
||||
else
|
||||
return
|
||||
}
|
||||
|
||||
Token :: union(TokenKind) {
|
||||
if i32
|
||||
else void
|
||||
return i32
|
||||
}
|
||||
|
||||
conditional func() TokenKind { return TokenKind.if }
|
||||
fallback func() TokenKind { return .else }
|
||||
token func() Token { return Token{ if = 1 } }
|
||||
```
|
||||
|
||||
Keyword variants also work with field access and `.variant` match patterns; `.else:` remains
|
||||
distinct from the `else:` catch-all arm. No escaping syntax is required. Keywords remain reserved
|
||||
for ordinary declarations, struct fields, untagged-union fields, and anonymous payload-struct
|
||||
fields. `_` is not a keyword member name.
|
||||
|
||||
### expressions and control flow
|
||||
|
||||
- checked integer `+ - *`, unary `-`, float-only `/`, IEEE float arithmetic, comparisons, `!`, `and`, and `or`
|
||||
|
||||
Reference in New Issue
Block a user