Skip to content

Commit e7c2fbf

Browse files
committed
remove more noisy docs; clean up docs
1 parent edffa5b commit e7c2fbf

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

exhaustive.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,6 @@ of the enum type's members are listed in the switch statement's cases. If
3838
multiple enum member constants have the same constant value, it is sufficient
3939
for any one of these same-valued members to be listed.
4040
41-
type Command int
42-
43-
const (
44-
Build Command = iota
45-
Test
46-
Default = Build
47-
)
48-
49-
func f(cmd Command) {
50-
// This switch statement is exhaustive. (The enum member Default does
51-
// not have to be listed, because it has the same value as Build.)
52-
switch cmd {
53-
case Build:
54-
case Test:
55-
}
56-
}
57-
5841
For an enum type defined in the same package as the switch statement, both
5942
exported and unexported enum members must be listed to satisfy exhaustiveness.
6043
For an enum type defined in an external package, it is sufficient that only
@@ -104,18 +87,15 @@ constant of the right type to be listed in the cases of an enum switch statement
10487
(it does not necessarily have to be a constant declared in the same scope/package
10588
as the enum type's scope/package).
10689
107-
Such a constant can contribute towards satisfying switch statement
108-
exhaustiveness if it has the same constant value as an actual enum member
109-
constant. The constant can be a substitute for the enum member constant in the
110-
switch statement's cases. This behavior is particularly useful when a type alias
111-
is involved: A constant (such as pkg.A, in type T1's package) can take the place
112-
of the actual enum member constant (such as otherpkg.A, in type T2's package) in
113-
the switch statement's cases.
90+
This is particularly useful when a type alias is involved: A forwarding constant
91+
declaration (such as const pkg.A = otherpkg.A, in type T1's package, from the
92+
earlier example) can take the place of the actual enum member constant
93+
(otherpkg.A, in type T2's package) in the switch statement's cases.
11494
11595
var v pkg.T1 = pkg.ReturnsT1() // in effect, v is of type otherpkg.T2 due to alias
11696
switch v {
117-
case pkg.A: // can be a substitute for otherpkg.A (both have same value)
118-
case pkg.B: // can be a substitute for otherpkg.B (both have same value)
97+
case pkg.A: // valid substitute for otherpkg.A (same constant value)
98+
case pkg.B: // valid substitute for otherpkg.B (same constant value)
11999
}
120100
121101
Flags

0 commit comments

Comments
 (0)