From dee7b873a6be907f594b76ee1b9bce4a0f5f68ef Mon Sep 17 00:00:00 2001 From: xgopilot Date: Mon, 27 Oct 2025 09:07:35 +0000 Subject: [PATCH] fix(ssa): extract PkgPath from any method, not just private methods The previous fix only extracted package path from private methods, causing segfaults for interfaces with only exported methods (like fs.DirEntry). Root cause: - For interfaces with only exported methods, the loop never entered the !token.IsExported(mName) block - pkgPath remained empty and fell back to pkg.Path() (compilation package) - This caused wrong PkgPath for standard library interfaces like fs.DirEntry - Runtime received wrong package path, leading to segfaults Fix: - Extract pkgPath from the FIRST method (any method), not just private ones - All methods have correct package information via m.Pkg() - Only fall back to pkg.Path() if the interface has no methods or m.Pkg() is nil This fixes the readdir demo segfault while maintaining the fix for issue #1370. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com> --- ssa/abitype.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ssa/abitype.go b/ssa/abitype.go index abf8a14f..6456cd2a 100644 --- a/ssa/abitype.go +++ b/ssa/abitype.go @@ -191,12 +191,12 @@ func (b Builder) abiInterfaceOf(t *types.Interface) func() Expr { for i := 0; i < n; i++ { m := t.Method(i) mName := m.Name() - if !token.IsExported(mName) { - if pkgPath == "" { - if mPkg := m.Pkg(); mPkg != nil { - pkgPath = mPkg.Path() - } + if pkgPath == "" { + if mPkg := m.Pkg(); mPkg != nil { + pkgPath = mPkg.Path() } + } + if !token.IsExported(mName) { mName = abi.FullName(m.Pkg(), mName) } methods[i] = b.abiImethodOf(mName, typs[i])