go/internal/gcimporter: support unique naming for blank type parameters
As described in golang/go#50481, in the existing export data schema
blank type parameters do not have unique names, and therefore types with
multiple blank (receiver) type parameters cannot be correctly imported.
This CL implements the fix proposed in that issue, using the schema
<prefix>.$<index> as the exported name of a blank type parameter, where
<prefix> is the qualifying prefix and <index> is the index of the type
parameter in its type parameter list. The importer is backwards
compatible with the old schema: it will continue to import <prefix>._ as
long as there are not multiple blank type parameters.
I considered not making the exporter change simultaneously with the
importer change, so that we interleave the corresponding changes in the
standard library. However, that made it harder to test the importer, and
updating both seems unlikely to cause problems.
For golang/go#50481
Change-Id: Id24428c6ea2b256312156894f9f76fa8e9ee38d4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/379855
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Dan Scales <danscales@google.com>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/go/internal/gcimporter/iimport.go b/go/internal/gcimporter/iimport.go
index 475b04d..1a33cd5 100644
--- a/go/internal/gcimporter/iimport.go
+++ b/go/internal/gcimporter/iimport.go
@@ -438,12 +438,7 @@
if r.p.version < iexportVersionGenerics {
errorf("unexpected type param type")
}
- // Remove the "path" from the type param name that makes it unique
- ix := strings.LastIndex(name, ".")
- if ix < 0 {
- errorf("missing path for type param")
- }
- name0 := name[ix+1:]
+ name0 := tparamName(name)
tn := types.NewTypeName(pos, r.currPkg, name0, nil)
t := typeparams.NewTypeParam(tn, nil)