别问我为什么要这么做,只要告诉我怎么可能:
gopls error: mismatched types string and string个
type Mapsi2[T string | int | float32 | float64] struct {
Keys []string
Values []T
}
func (mapsi Mapsi2[string]) SetValue(key string, value string) {
for i, keyMapsi := range mapsi.Keys {
if key == keyMapsi {
mapsi.Values[i] = value
}
}
}
起初,我认为LSP服务器很愚蠢,但事实证明并非如此.
go error: mismatched types string and string个
go run ./cmd/app
# devllart/foobarman/src/mapsi
src/mapsi/mapsi.go:48:13: invalid operation: key == keyMapsi (mismatched types string and string)
make: *** [Makefile:6: run] Error 2
我在谷歌上搜索,在搜索结果中,只有比较指针和字符串的错误...就在那里,所有的类型都是正常的,否则我就错了.