docs: add axample of escaping a v keyword in enums (#8425)

pull/8433/head
William Gooch 2021-01-29 14:09:24 -05:00 committed by GitHub
parent 4a955d9c54
commit b8d93df55e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -1928,6 +1928,21 @@ match color {
Enum match must be exhaustive or have an `else` branch. Enum match must be exhaustive or have an `else` branch.
This ensures that if a new enum field is added, it's handled everywhere in the code. This ensures that if a new enum field is added, it's handled everywhere in the code.
Enum fields cannot re-use reserved keywords. However, reserved keywords may be escaped
with an @.
```v
enum Color {
@none
red
green
blue
}
color := Color.@none
println(color)
```
### Sum types ### Sum types
A sum type instance can hold a value of several different types. Use the `type` A sum type instance can hold a value of several different types. Use the `type`