]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/compile: make sure multiple blank typeparams remain unique
authorDan Scales <danscales@google.com>
Tue, 18 Jan 2022 20:55:17 +0000 (12:55 -0800)
committerDan Scales <danscales@google.com>
Fri, 21 Jan 2022 00:39:55 +0000 (00:39 +0000)
commit32636cd1ffc6cd9ef81d09b8320d2aaad4a21117
tree76ef77c1dc05ceb0eef3b7c279d3f0b971e4b100
parent2c2e08144f79d8746384c2a483bf03532dc0c443
cmd/compile: make sure multiple blank typeparams remain unique

In a method declaration "func (f *Foo[_, _]) String() string { ... }",
the two blank typeparams have the same name, but our current design with
types1 needs unique names for type params. Similarly, for export/import,
we need unique names to keep the type params straight in generic types
and connect the proper type param with the proper constraint. We make
blank type params unique by changing them to $1, $2, etc in noder.typ0()
via typecheck.TparamExportName(). We then revert $<num> back to _ during
type2 import via typecheck.TparamName(). We similarly revert
during gcimporter import. We don't need/want to revert in the types1
importer, since we want unique names for type params.

Rob Findley has made a similar change to x/tools (and we tried to make
the source code changes similar for the gcimporter and types2 importer
changes).

Fixes #50419

Change-Id: I855cc3d90d06bcf59541ed0c879e9a0e4ede45bb
Reviewed-on: https://go-review.googlesource.com/c/go/+/379194
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>
15 files changed:
src/cmd/compile/internal/importer/iimport.go
src/cmd/compile/internal/noder/types.go
src/cmd/compile/internal/typecheck/iexport.go
src/cmd/compile/internal/types2/decl.go
src/go/internal/gcimporter/iimport.go
src/go/types/decl.go
test/typeparam/issue50419.go [new file with mode: 0644]
test/typeparam/issue50481.go [deleted file]
test/typeparam/issue50481b.dir/b.go [new file with mode: 0644]
test/typeparam/issue50481b.dir/main.go [new file with mode: 0644]
test/typeparam/issue50481b.go [new file with mode: 0644]
test/typeparam/issue50481c.dir/a.go [new file with mode: 0644]
test/typeparam/issue50481c.dir/main.go [new file with mode: 0644]
test/typeparam/issue50481c.go [new file with mode: 0644]
test/typeparam/issue50481c.out [new file with mode: 0644]