On Sat, Dec 31, 2016 at 3:26 AM, Uwe Dauernheim <u...@dauernheim.net> wrote: > It seem a float64 of value 0.0 as types interface{} can't be compared equal > to 0 in an exhaustive case clause type list, but can be compared equal in > almost any other scenario. > > https://play.golang.org/p/t2u2GGp565 > > I find this unexpected. Could someone explain how case clause type lists in > type assertions work? > The language specification states: > >> In clauses with a case listing exactly one type, the variable has that >> type; otherwise, the variable has the type of the expression in the >> TypeSwitchGuard. > > In the provided playground is no TypeSwitchGuard given, so this rule should > not affect behaviour.
switch g := f.(type) { case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64: //g is of type interface{} } "the expression in the TypeSwitchGuard" is 'f' which is of type interface{} in this case. Thus 'g' has the type interface{} within the case. The comparison 'g == 0' is false because 'g' contains a float64 and 0 is an int. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.