Go 无法推断类型分配 : "non-name on left side of :="

标签 go type-inference

此代码段按预期工作 play.golang.org/p/VuCl-OKMav

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

然而,这个几乎相同的片段在 := 的左侧给出了 non-name f.Bar play.golang.org/p/J8NNWPugQG

type Foo struct {
    Bar int
}

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

停止类型推断的结构有什么特别之处?这是一个错误吗?

最佳答案

这是一个 open 问题。

Issue 6842 : 规范:分配给具有简短声明符号的字段

关于Go 无法推断类型分配 : "non-name on left side of :=",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21345274/

相关文章:

mongodb - 使用 mgo Golang 从 MongoDB 子文档数组中解码

debugging - 从 Windows 交叉编译到 Linux 时出现错误?

functional-programming - 自底向上 Hindley-Milner 类型推断 : Applying a substitution to an implicit constraint

haskell - 函数签名如何匹配请求的类型

转到 RPC 错误 : reading body gob: attempt to decode into a non-pointer

arrays - Go:数组的数组, slice 的数组,数组的 slice 和 slice 的 slice

go - 如何在 KrakenD 中使用带有 TLS 的客户端?

c# - 嵌套泛型 : Why can't the compiler infer the type arguments in this case?

haskell - Haskell(GHC)中使用什么算法来推导递归表达式的类型?

javascript - typescript 无法推断自定义 Hook 中的解构数组类型