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

前端 未结 3 1107
深忆病人
深忆病人 2020-12-06 09:10

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

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

Ho

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 09:48

    It's not really a type inference issue, it's just that the left-hand-side of := must be a list of identifiers, and f.Bar is not an identifier, so it can't be declared — not even with :='s slightly-more-permissive rules for what it can declare. See "Short variable declarations" in The Go Programming Language Specification.

提交回复
热议问题