In that code, isn't the interface{} typing overridden by the value assigned to it? The override is compile-time, isn't it? Otherwise that condition would not evaluate to true. If you change the assignment to any other value the code will fall right through and no case will be executed.
On Sunday, 22 April 2018 11:40:25 UTC+3, Jérôme Champion wrote: > > The syntax is correct: https://play.golang.org/p/t5Oi8vyCsbw > I don't think comparing an interface to a boolean in a switch is very > common. It would need some strong evidence to justify adding an exception > to the rule. > > Le dimanche 22 avril 2018 02:53:14 UTC+2, Louki Sumirniy a écrit : >> >> Your syntax is wrong. I think you mean this: >> >> var someInterfaceValue interface{} >> >> // do something that puts a value in above variable >> >> switch someInterfaceValue { >> case true: >> // do something >> default: >> // do something else >> } >> >> On Saturday, 21 April 2018 16:30:22 UTC+3, b97...@gmail.com wrote: >>> >>> var someInterfaceValue interface{} >>> switch { >>> case someInterfaceValue: // proposal: compile error: non-bool used >>> as condition >>> case someInterfaceValue == true: // OK >>> } >>> >>> Sometimes carefulness is just not enough. >>> One may type a wrong variable as the case condition, or a incomplete >>> condition. >>> Why is this special? Because it's commonly used. >>> >> -- 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.