internal/typeparams: improve the panic in OriginMethod

Improve the panic message to help debug golang/go#61196.

Updates golang/go#61196

Change-Id: Ia3ab9583886d67b971914310e82a99a1a2b15a59
Reviewed-on: https://go-review.googlesource.com/c/tools/+/508795
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Rob Findley 2023-07-11 11:18:33 -04:00 коммит произвёл Robert Findley
Родитель 89d9fae1d1
Коммит 12fe14902a
4 изменённых файлов: 9 добавлений и 3 удалений

Просмотреть файл

@ -55,7 +55,7 @@ func importMap(imports []*types.Package) map[string]*types.Package {
// infinite expansions:
// type N[T any] struct { F *N[N[T]] }
// importMap() is called on such types when Analyzer.RunDespiteErrors is true.
T = typeparams.NamedTypeOrigin(T).(*types.Named)
T = typeparams.NamedTypeOrigin(T)
if !typs[T] {
typs[T] = true
addObj(T.Obj())

Просмотреть файл

@ -23,6 +23,7 @@
package typeparams
import (
"fmt"
"go/ast"
"go/token"
"go/types"
@ -125,6 +126,11 @@ func OriginMethod(fn *types.Func) *types.Func {
}
}
// In golang/go#61196, we observe another crash, this time inexplicable.
if gfn == nil {
panic(fmt.Sprintf("missing origin method for %s.%s; named == origin: %t, named.NumMethods(): %d, origin.NumMethods(): %d", named, fn, named == orig, named.NumMethods(), orig.NumMethods()))
}
return gfn.(*types.Func)
}

Просмотреть файл

@ -129,7 +129,7 @@ func NamedTypeArgs(*types.Named) *TypeList {
}
// NamedTypeOrigin is the identity method at this Go version.
func NamedTypeOrigin(named *types.Named) types.Type {
func NamedTypeOrigin(named *types.Named) *types.Named {
return named
}

Просмотреть файл

@ -103,7 +103,7 @@ func NamedTypeArgs(named *types.Named) *TypeList {
}
// NamedTypeOrigin returns named.Orig().
func NamedTypeOrigin(named *types.Named) types.Type {
func NamedTypeOrigin(named *types.Named) *types.Named {
return named.Origin()
}