This happens all of the time for enums in structs especially during (de)serialization and returning a zero value and an error.
func DeserializeState(raw []byte) (State, error) {
type Foo struct {
State state `json:"state"`
Data map[string]string `json:"data"`
}
f := Foo{}
err := json.Unmarshal(&foo, raw)
if err != nil {
return ???, err
}
}
s := DeserializeState([]byte(`{"data": {"key": "value"}}`)
fmt.Println(s) // prints 0 oops
Your example case is something that I can't think of a reason to do. It isn't a case where you would need to be careful and knowledgeable to avoid it - there's just no reason to do it. You would use On and Off instead of defining a variable with this type.