1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

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

This commit is contained in:
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

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`