Go 无法推断赋值中的类型:“:= 左侧的非名称"; [英] Go fails to infer type in assignment: "non-name on left side of :="
本文介绍了Go 无法推断赋值中的类型:“:= 左侧的非名称";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码段按预期工作 play.golang.org/p/VuCl-OKMav
i := 10
next := 11
prev, i := i, next
然而,这个几乎相同的代码段在 := 的左侧给出了 非名称 f.Bar
play.golang.org/p/J8NNWPugQG
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?
推荐答案
这是一个 open 问题.
问题 6842:规范:分配给具有简短声明符号的字段
Issue 6842: spec: Assigning to fields with short declaration notation
这篇关于Go 无法推断赋值中的类型:“:= 左侧的非名称";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文