You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
type Color bool;
const (
Black = false;
White = true;
)
func (c Color) String() string {
switch c {
case White: return "White";
case Black: return "Black";
}
panic("not reachable");
}
What is the expected output? What do you see instead?
I think this should compile, but I get:
gongo.go:66: case true (type bool) in Color switch
gongo.go:66: case false (type bool) in Color switch
What is your $GOOS? $GOARCH?
$ echo $GOOS $GOARCH
darwin 386
Which revision are you using? (hg identify)
$ hg identify
44699e529c44+ tip
An easy workaround is to rewrite it like this:
switch {
case c == White: return "White";
case c == Black: return "Black";
}
The text was updated successfully, but these errors were encountered:
Never mind. The correct way to write this is:
type Color bool;
const (
Black = Color(false);
White = Color(true);
)
func (c Color) String() string {
switch (c) {
case White: return "White";
case Black: return "Black";
}
panic("not reachable");
}
The types Color and bool are assignment compatible so you don't really need the
conversion - you just need to specify the Color type in the const declaration:
const (
Black, White Color = false, true;
)
Issue closed - this is not a bug. The code below works as expected.
package main
type Color bool;
const (
Black Color = false;
White Color = true;
)
func (c Color) String() string {
switch c {
case White: return "White";
case Black: return "Black";
}
panic("not reachable");
}
func main() {
println(Black.String());
println(White.String());
}
by bslesinsky:
The text was updated successfully, but these errors were encountered: