Reverted two unnecessary formatting changes based on code review:
- ssa/interface.go: Restored single-line format for val function
- ssa/abitype.go: Moved pkg variable declaration back to original position
These changes don't affect functionality, just code formatting.
Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
Based on meeting discussion, this commit reverts the previous approach
of extracting PkgPath from interface methods. Instead, anonymous
interfaces now use an empty PkgPath string, and the runtime's methods()
function handles empty PkgPath by returning all methods.
Changes:
- Reverted unsafeInterface() to remove originType parameter
- Set anonymous interface PkgPath to empty string in abitype.go:202
- Added early return in methods() in z_face.go for empty PkgPath
- All call sites of unsafeInterface() updated to pass rawIntf directly
This approach is cleaner because anonymous interfaces don't belong to
any package, and the compiler already guarantees safety for cross-package
private method access.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
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>