fix: preserve Named interface type information through interface construction

This commit addresses the root cause identified in issue #1370 by preserving
Named interface type information through the interface construction phase.

**Root Cause:**
Named interfaces were prematurely unwrapped via Underlying() in the interface
construction phase (MakeInterface()/unsafeInterface()), causing the subsequent
ABI type generation to hit `case *types.Interface:` instead of
`case *types.Named:`, resulting in loss of package information.

**The Fix:**
1. Modified `unsafeInterface()` to accept a `namedIntf types.Type` parameter
2. Updated all callers to pass the Named type (tinter.raw.Type, assertedTyp.raw.Type, etc.)
3. When namedIntf is available, pass it to `abiType()` to ensure proper routing
   through the type switch to `abiNamedInterfaceOf()` which has correct package context
4. Reverted the workaround logic in `abiInterfaceOf()` that extracted pkgPath from methods

**Impact:**
- Fixes segmentation faults when calling interface private methods across packages
- Ensures runtime receives correct package path for interface metadata
- Allows private method slots in itab to be properly filled

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
xgopilot
2025-10-28 10:31:43 +00:00
parent ebd041082b
commit 05da9ec252
3 changed files with 34 additions and 350 deletions

View File

@@ -186,29 +186,20 @@ func (b Builder) abiInterfaceOf(t *types.Interface) func() Expr {
}
return func() Expr {
prog := b.Prog
pkg := b.Pkg
methods := make([]Expr, n)
pkgPath := ""
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 = abi.PathOf(mPkg)
}
}
mName = abi.FullName(m.Pkg(), mName)
}
methods[i] = b.abiImethodOf(mName, typs[i])
}
pkg := b.Pkg
if pkgPath == "" {
pkgPath = pkg.Path()
}
fn := pkg.rtFunc("Interface")
tSlice := lastParamType(prog, fn)
methodSlice := b.SliceLit(tSlice, methods...)
return b.Call(fn, b.Str(pkgPath), methodSlice)
return b.Call(fn, b.Str(pkg.Path()), methodSlice)
}
}