1
0
mirror of https://github.com/golang/go synced 2024-07-05 09:50:19 +00:00
go/test/typeparam/issue50481c.dir/a.go
Dan Scales 32636cd1ff 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>
2022-01-21 00:39:55 +00:00

31 lines
419 B
Go

// Copyright 2022 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 a
type A interface {
int | int64
}
type B interface {
string
}
type C interface {
String() string
}
type Myint int
func (i Myint) String() string {
return "aa"
}
type T[P A, _ C, _ B] int
func (v T[P, Q, R]) test() {
var r Q
r.String()
}