Go fails to infer type in assignment: "non-name on left side of :="

deft_code picture deft_code · Jan 25, 2014 · Viewed 31.4k times · Source

This snippet works as expected play.golang.org/p/VuCl-OKMav

i := 10
next := 11
prev, i := i, next

However this nearly identical snippet gives non-name f.Bar on left side of := play.golang.org/p/J8NNWPugQG

type Foo struct {
    Bar int
}

f := Foo{10}
next := 11
prev, f.Bar := f.Bar, next

What's special about the struct that stops type inference? Is this a bug?

Answer

peterSO picture peterSO · Jan 25, 2014

It's an open issue.

Issue 6842: spec: Assigning to fields with short declaration notation