Skip to content

Commit

Permalink
clarify doc example
Browse files Browse the repository at this point in the history
  • Loading branch information
nishanths committed Nov 11, 2021
1 parent bf7c718 commit a070607
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions exhaustive.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ using explicit values, or by any means of declaring a valid Go const. It is
allowed for multiple enum members for a given enum type to have the same
constant value.
type Command int
const (
Build Command = iota
Test
)
const Default = Build
Definition of exhaustiveness
A switch statement that switches on a value of an enum type is exhaustive if all
of the enum type's members are listed in the switch statement's cases. If
multiple enum member constants have the same constant value, it is sufficient
for any one of these same-valued members to be listed.
type Command int
const (
Build Command = iota
Test
Default = Build
)
func f(cmd Command) {
// This switch statement is exhaustive.
// (The enum member Default does not have to be listed, because
// it has the same value as Build.)
switch cmd {
case Build:
case Test:
Expand Down

0 comments on commit a070607

Please sign in to comment.