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>
This commit is contained in:
xgopilot
2025-10-27 09:07:35 +00:00
parent b3d123e235
commit dee7b873a6

View File

@@ -191,12 +191,12 @@ func (b Builder) abiInterfaceOf(t *types.Interface) func() Expr {
for i := 0; i < n; i++ { for i := 0; i < n; i++ {
m := t.Method(i) m := t.Method(i)
mName := m.Name() mName := m.Name()
if !token.IsExported(mName) { if pkgPath == "" {
if pkgPath == "" { if mPkg := m.Pkg(); mPkg != nil {
if mPkg := m.Pkg(); mPkg != nil { pkgPath = mPkg.Path()
pkgPath = mPkg.Path()
}
} }
}
if !token.IsExported(mName) {
mName = abi.FullName(m.Pkg(), mName) mName = abi.FullName(m.Pkg(), mName)
} }
methods[i] = b.abiImethodOf(mName, typs[i]) methods[i] = b.abiImethodOf(mName, typs[i])