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>
12 lines
207 B
Go
12 lines
207 B
Go
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())
|
|
}
|