allow keywords as values in enums (and tagged unions)

This commit is contained in:
2026-07-13 17:51:59 +02:00
parent de56dc7315
commit 5a958d9bfd
5 changed files with 156 additions and 18 deletions
+28
View File
@@ -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`