mirror of
https://github.com/golang/go
synced 2024-11-02 13:42:29 +00:00
5b64381155
Issues 47713 and 47877 were both due to problems with the names used for instantiated functions/methods, which must be in sync with the names used by types2. - Switched to using NameString() for writing out type arguments in instantiation names. This ensures that we are always adding the package to type names even for the local package. Previously, we were explicitly adding the package name for local packages, but that doesn't handle the case when the local type is embedded inside a pointer or slice type. By switching to NameString(), we fix #47713. - types1 and types2 write out 'interface {' differently (vs. 'interface{') and we were already handling that. But we needed to add similar code to handle 'struct {' vs 'struct{'. This fixes issue #47877. While fixing these bugs, I also moved some duplicated code (which include some of the changes above) into a common function addTargs(). I also moved InstType() name to subr.go, and renamed: MakeInstName -> MakeFuncInstSym and MakeDictName -> MakeDictSym. Also removed a couple of ".inst..inst." prefix checks which are irrelvant now, since we don't add ".inst." anymore to function instantiations. Fixes #47713 Fixes #47877 Fixes #47922 Change-Id: I19e9a073451f3ababd8ec31b6608cd79ba8cba36 Reviewed-on: https://go-review.googlesource.com/c/go/+/344613 Trust: Dan Scales <danscales@google.com> Reviewed-by: Keith Randall <khr@golang.org>
23 lines
458 B
Go
23 lines
458 B
Go
// run -gcflags=-G=3
|
|
|
|
// Copyright 2021 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
type Map[K comparable, V any] struct {
|
|
m map[K]V
|
|
}
|
|
|
|
func NewMap[K comparable, V any]() Map[K, V] {
|
|
return Map[K, V]{m: map[K]V{}}
|
|
}
|
|
|
|
func (m Map[K, V]) Get(key K) V {
|
|
return m.m[key]
|
|
}
|
|
|
|
func main() {
|
|
_ = NewMap[int, struct{}]()
|
|
}
|