mirror of
https://github.com/golang/go
synced 2024-11-23 21:40:05 -07:00
reflect: fix name of type parameter
Fixes #50208 Change-Id: Ib0aff56341adb98ff6831c5badd1603ebf002b79 Reviewed-on: https://go-review.googlesource.com/c/go/+/372774 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Trust: Cherry Mui <cherryyz@google.com>
This commit is contained in:
parent
7f2314530e
commit
1d3a5b4aea
@ -7768,3 +7768,17 @@ func TestMethodCallValueCodePtr(t *testing.T) {
|
||||
t.Errorf("methodValueCall code pointer mismatched, want: %v, got: %v", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
type A struct{}
|
||||
type B[T any] struct{}
|
||||
|
||||
func TestIssue50208(t *testing.T) {
|
||||
want1 := "B[reflect_test.A]"
|
||||
if got := TypeOf(new(B[A])).Elem().Name(); got != want1 {
|
||||
t.Errorf("name of type parameter mismatched, want:%s, got:%s", want1, got)
|
||||
}
|
||||
want2 := "B[reflect_test.B[reflect_test.A]]"
|
||||
if got := TypeOf(new(B[B[A]])).Elem().Name(); got != want2 {
|
||||
t.Errorf("name of type parameter mismatched, want:%s, got:%s", want2, got)
|
||||
}
|
||||
}
|
||||
|
@ -915,7 +915,14 @@ func (t *rtype) Name() string {
|
||||
}
|
||||
s := t.String()
|
||||
i := len(s) - 1
|
||||
for i >= 0 && s[i] != '.' {
|
||||
sqBrackets := 0
|
||||
for i >= 0 && (s[i] != '.' || sqBrackets != 0) {
|
||||
switch s[i] {
|
||||
case ']':
|
||||
sqBrackets++
|
||||
case '[':
|
||||
sqBrackets--
|
||||
}
|
||||
i--
|
||||
}
|
||||
return s[i+1:]
|
||||
|
Loading…
Reference in New Issue
Block a user