Add three regression test cases for cross-package interface private method calls: 1. _cmptest/issue1370_gotypes/ - Tests go/types.Object interface with Scope.Insert() which calls the private setParent() method 2. _cmptest/issue1370_goast/ - Tests go/ast.Expr interface conversion with ast.Ident which has a private exprNode() method 3. _cmptest/issue1370_geometry/ - Tests custom geometry.Shape interface with private methods (validate, setID) across package boundaries These tests verify the fix in ssa/abitype.go correctly sets the interface metadata's PkgPath to the interface definition package instead of the compilation package, preventing segmentation faults when calling private methods. Generated with [codeagent](https://github.com/qbox/codeagent) Co-authored-by: luoliwoshang <51194195+luoliwoshang@users.noreply.github.com>
27 lines
579 B
Go
27 lines
579 B
Go
package geometry
|
|
|
|
type Shape interface {
|
|
Area() float64
|
|
validate() bool
|
|
setID(int)
|
|
}
|
|
|
|
type Rectangle struct {
|
|
Width, Height float64
|
|
id int
|
|
}
|
|
|
|
func (r *Rectangle) Area() float64 { return r.Width * r.Height }
|
|
func (r *Rectangle) validate() bool { return r.Width > 0 && r.Height > 0 }
|
|
func (r *Rectangle) setID(id int) { r.id = id }
|
|
func (r *Rectangle) GetID() int { return r.id }
|
|
|
|
func NewRectangle(width, height float64) *Rectangle {
|
|
return &Rectangle{Width: width, Height: height}
|
|
}
|
|
|
|
func RegisterShape(s Shape, id int) error {
|
|
s.setID(id)
|
|
return nil
|
|
}
|