mirror of
https://github.com/golang/go
synced 2024-11-24 07:00:13 -07:00
runtime: fix name of type parameter
CL 372774 is for reflect, this CL is for _type in runtime. Add a test case to ensure the name method of _type can be exercised. Updates #50208 Change-Id: I26ccf8c5c574dd9e78510cf29eb40ae7c8d449ab Reviewed-on: https://go-review.googlesource.com/c/go/+/393917 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
ff14e844d2
commit
ec5e5dba6f
@ -67,3 +67,29 @@ func TestWriteHeapDumpFinalizers(t *testing.T) {
|
||||
WriteHeapDump(f.Fd())
|
||||
println("done dump")
|
||||
}
|
||||
|
||||
type G[T any] struct{}
|
||||
type I interface {
|
||||
M()
|
||||
}
|
||||
|
||||
//go:noinline
|
||||
func (g G[T]) M() {}
|
||||
|
||||
var dummy I = G[int]{}
|
||||
var dummy2 I = G[G[int]]{}
|
||||
|
||||
func TestWriteHeapDumpTypeName(t *testing.T) {
|
||||
if runtime.GOOS == "js" {
|
||||
t.Skipf("WriteHeapDump is not available on %s.", runtime.GOOS)
|
||||
}
|
||||
f, err := os.CreateTemp("", "heapdumptest")
|
||||
if err != nil {
|
||||
t.Fatalf("TempFile failed: %v", err)
|
||||
}
|
||||
defer os.Remove(f.Name())
|
||||
defer f.Close()
|
||||
WriteHeapDump(f.Fd())
|
||||
dummy.M()
|
||||
dummy2.M()
|
||||
}
|
||||
|
@ -127,7 +127,14 @@ func (t *_type) 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