fix(ssa): correct PkgPath for interface metadata in cross-package conversions
Fixes #1370 - Segmentation Fault When Calling Interface Private Methods Cross-Package This commit fixes a critical bug where interface metadata's PkgPath was incorrectly set when converting concrete type pointers to interfaces with private methods across package boundaries. Problem: - When a concrete type pointer was converted to an interface with private methods in a package different from the interface definition package, the compiler incorrectly set the interface metadata's PkgPath to the current compilation package instead of the interface definition package - This caused the runtime to only fill exported methods in the itab, leaving private method slots as NULL (0x0), resulting in segmentation faults Solution: - Modified abiInterfaceOf() in ssa/abitype.go to extract the package path from the interface's private methods (if any) - Use that package path instead of the current compilation package path - Fall back to current package path only if all methods are exported Changes: - ssa/abitype.go: Use abi.PathOf() to get correct package path - ssa/interface.go: Refactor to simplify interface type handling - Added comprehensive test cases and demos for go/types, go/token, and go/ast - Updated all test outputs to reflect correct interface metadata generation This fix resolves segmentation faults when using Go standard library interfaces and user-defined interfaces with private methods across package boundaries. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
This commit is contained in:
11
cl/_testgo/interface1370/in.go
Normal file
11
cl/_testgo/interface1370/in.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/goplus/llgo/cl/_testdata/geometry1370"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rect := geometry1370.NewRectangle(5.0, 3.0)
|
||||
geometry1370.RegisterShape(rect, 42)
|
||||
println("ID:", rect.GetID())
|
||||
}
|
||||
Reference in New Issue
Block a user