This works: b, a := 1, struct{ x int }{2}
But this doesn’t: var a struct{ x int } b, a.x := Returns1And2() But this does: var a struct{ x int } var b int b, a.x = Returns1And2() And this does: var a int b, a := Returns1And2() Matt On Tuesday, January 9, 2018 at 5:59:49 PM UTC-6, Kevin Malachowski wrote: > > It is not a new declaration, it is definitely an assignment. This can be > determined because (in Go) a new declaration has effects when closing over > variables: https://play.golang.org/p/a_IZdOWeqYf > > (ignore the obvious race condition; it works the same but looks uglier > with the requisite locks: https://play.golang.org/p/OXBK5XEg9Yf) > > On Tuesday, January 9, 2018 at 2:20:06 PM UTC-8, Ayan George wrote: >> >> >> >> On 01/09/2018 04:45 PM, Ian Lance Taylor wrote: >> > On Tue, Jan 9, 2018 at 1:02 PM, Jim Bishopp >> > <james....@gmail.com> wrote: >> >> >> >> Has there ever been a discussion about allowing new identifiers and >> >> selectors in short variable declarations? >> >> >> >> var a struct { x int } b, a.x := 1, 2 >> >> >> >> ERROR: expected identifier on left side of := >> > >> > That idea appears in https://golang.org/issue/377, along with many >> > others. >> > >> >> I had the same question myself. I settled on the idea that that is a >> short declaration -- not an assignment -- though it does re-declare >> existing variables (of the same type!). That behaves like assignment >> but I think it is still declaration. >> >> But its behavior makes sense if you consider that you can't declare or >> re-declare struct member. >> >> -ayan >> > -- 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.