diff --git a/cache_pkg.go b/cache_pkg.go index 5b31708..8f0c2b4 100644 --- a/cache_pkg.go +++ b/cache_pkg.go @@ -20,8 +20,8 @@ import ( ) type ( - funcFullName = string // as per go/types.Func.FullName - objectString = string // as per recordedObjectString + funcFullName = string // the result of [types.Func.FullName] plus [stripTypeArgs] + objectString = string // the result of [reflectInspector.obfuscatedObjectName] ) // pkgCache contains information about a package that will be stored in fsCache. @@ -45,17 +45,6 @@ func (c *pkgCache) CopyFrom(c2 pkgCache) { maps.Copy(c.ReflectObjectNames, c2.ReflectObjectNames) } -func decodePkgCache(r io.Reader, dst *pkgCache) error { - // Decode into a fresh value first: gob merges into non-nil maps, so decoding - // directly into dst can leave stale entries in nested maps. - var decoded pkgCache - if err := gob.NewDecoder(r).Decode(&decoded); err != nil { - return fmt.Errorf("gob decode: %w", err) - } - dst.CopyFrom(decoded) - return nil -} - func ssaBuildPkg(pkg *types.Package, files []*ast.File, info *types.Info) *ssa.Package { // Create SSA packages for all imports. Order is not significant. ssaProg := ssa.NewProgram(fset, 0) @@ -190,7 +179,8 @@ func computePkgCache(fsCache *cache.Cache, lpkg *listedPackage, pkg *types.Packa return err } defer f.Close() - if err := decodePkgCache(f, &computed); err != nil { + // The gob decoder + if err := gob.NewDecoder(f).Decode(&computed); err != nil { return err } return nil diff --git a/reflect.go b/reflect.go index 902d774..01096f8 100644 --- a/reflect.go +++ b/reflect.go @@ -235,11 +235,7 @@ func (ri *reflectInspector) checkFunction(fun *ssa.Function) { // fun.WriteTo(os.Stdout) // } - originFun := fun.Origin() - if originFun == nil { - originFun = fun - } - f, _ := originFun.Object().(*types.Func) + f, _ := ssaFuncOrigin(fun).Object().(*types.Func) var funcName string genericFunc := false if f != nil { @@ -281,16 +277,8 @@ func (ri *reflectInspector) checkFunction(fun *ssa.Function) { case *ssa.Call: callName := "" if callee := inst.Call.StaticCallee(); callee != nil { - if obj, ok := callee.Object().(*types.Func); ok && obj != nil { + if obj, ok := ssaFuncOrigin(callee).Object().(*types.Func); ok && obj != nil { callName = obj.FullName() - } else { - originCallee := callee.Origin() - if originCallee == nil { - originCallee = callee - } - if obj, ok := originCallee.Object().(*types.Func); ok && obj != nil { - callName = obj.FullName() - } } } if callName == "" && inst.Call.Method != nil { @@ -648,3 +636,10 @@ func stripTypeArgs(name string) (string, bool) { } return b.String(), true } + +func ssaFuncOrigin(fn *ssa.Function) *ssa.Function { + if orig := fn.Origin(); orig != nil { + return orig + } + return fn +} diff --git a/reverse.go b/reverse.go index 69136eb..f425d53 100644 --- a/reverse.go +++ b/reverse.go @@ -105,9 +105,6 @@ One can reverse a captured panic stack trace as follows: } originObj := obj.Origin() strct := fieldToStruct[originObj] - if strct == nil { - strct = fieldToStruct[obj] - } if strct == nil { panic("could not find struct for field " + name.Name) }