diff --git a/_cmptest/issue1370_geometry/geometry.go b/_cmptest/issue1370_geometry/geometry.go new file mode 100644 index 00000000..e4fb68db --- /dev/null +++ b/_cmptest/issue1370_geometry/geometry.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + + "github.com/goplus/llgo/_cmptest/issue1370_geometry/geometry" +) + +func main() { + rect := geometry.NewRectangle(5.0, 3.0) + + err := geometry.RegisterShape(rect, 42) + if err != nil { + println("FAIL: RegisterShape returned error") + return + } + + if rect.GetID() != 42 { + println("FAIL: ID not set correctly") + return + } + + area := rect.Area() + fmt.Printf("Area: %.1f\n", area) + + if area != 15.0 { + println("FAIL: Area calculation incorrect") + return + } + + println("SUCCESS: Custom interface with private methods works correctly") +} diff --git a/_cmptest/issue1370_geometry/geometry/geometry.go b/_cmptest/issue1370_geometry/geometry/geometry.go new file mode 100644 index 00000000..af4b3272 --- /dev/null +++ b/_cmptest/issue1370_geometry/geometry/geometry.go @@ -0,0 +1,26 @@ +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 +} diff --git a/_cmptest/issue1370_goast/goast.go b/_cmptest/issue1370_goast/goast.go new file mode 100644 index 00000000..44a92d05 --- /dev/null +++ b/_cmptest/issue1370_goast/goast.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "go/ast" + "go/token" +) + +func main() { + ident := &ast.Ident{ + NamePos: token.Pos(42), + Name: "foo", + } + + var expr ast.Expr = ident + pos := expr.Pos() + + fmt.Printf("Position: %d\n", pos) + if pos != 42 { + println("FAIL: Position mismatch") + return + } + + println("SUCCESS: ast.Expr interface method calls work correctly") +} diff --git a/_cmptest/issue1370_gotypes/gotypes.go b/_cmptest/issue1370_gotypes/gotypes.go new file mode 100644 index 00000000..6ac15c7f --- /dev/null +++ b/_cmptest/issue1370_gotypes/gotypes.go @@ -0,0 +1,24 @@ +package main + +import ( + "go/types" +) + +func main() { + scope := types.NewScope(nil, 0, 0, "test") + obj := types.NewVar(0, nil, "x", types.Typ[types.Int]) + + scope.Insert(obj) + + retrieved := scope.Lookup("x") + if retrieved == nil { + println("FAIL: Lookup returned nil") + return + } + if retrieved.Name() != "x" { + println("FAIL: Name mismatch") + return + } + + println("SUCCESS: Scope.Insert and Lookup work correctly") +}