暂时不建议更新go1.18正式版

aries 发表于 2022-03-16 680 次浏览

通过刚才的测试
发现 goland 对泛型支持有 bug ,能正常编译的代码报错,先降回 1.17 了
复现代码

package main

import "fmt"

type G[T any] struct {
	Data []T
}

type D = G[int] // <- type alias or type definition both can trigger this bug.

func main() {
	g := D{
		Data: make([]int, 0), // goland will report a type error here.
	}
	fmt.Println(g)
}

0条评论

如需评论,请填写表单。
换一个

记住我的信息