On Wednesday, August 24, 2016 at 10:22:22 PM UTC-7, Ian Lance Taylor wrote: > > On Wed, Aug 24, 2016 at 9:21 PM, sbkim via golang-nuts > <golan...@googlegroups.com <javascript:>> wrote: > > Hello group, > > > > Why are the following snippets errors? > > > > https://play.golang.org/p/mgEYMNNw9h > > type S struct { > > i int > > } > > > > if S{i: 0} == S{} { > > } > > syntax error: unexpected == at end of statement > > > > switch S{i: 0} == S{} { > > } > > syntax error: unexpected i, expecting case or default or } > > > > It works without error if you surround each literal with ( ), or the > entire > > comparison expression with ( ). > > The following also works without error: > > _ = S{i: 0} == S{} > > > > Does the language spec state those are errors, or is this a bug in the > > parser? > > Search for "parsing ambiguity" in > https://golang.org/ref/spec#Composite_literals . >
Why hadn't I found that? Thanks for the pointer! I guess this has to do with the fact that the parser doesn't care whether S is a type name or not. -- 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.