Skip to content

Commit

Permalink
Merge pull request #1592 from visualfc/overload_iface
Browse files Browse the repository at this point in the history
update gox support interface overload method
  • Loading branch information
xushiwei committed Dec 26, 2023
2 parents f99f847 + 2834233 commit db2caf2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
71 changes: 71 additions & 0 deletions cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5019,3 +5019,74 @@ func main() {
}
`)
}

func TestMixedInterfaceOverload(t *testing.T) {
gopMixedClTest(t, "main", `
package main
type N[T any] struct {
v T
}
func (m *N[T]) OnKey__0(a string, fn func()) {
}
func (m *N[T]) OnKey__1(a string, fn func(key string)) {
}
func (m *N[T]) OnKey__2(a []string, fn func()) {
}
func (m *N[T]) OnKey__3(a []string, fn func(key string)) {
}
type I interface {
OnKey__0(a string, fn func())
OnKey__1(a string, fn func(key string))
OnKey__2(a []string, fn func())
OnKey__3(a []string, fn func(key string))
}
`, `
n := &N[int]{}
n.onKey "1", => {
}
keys := ["1","2"]
n.onKey keys, key => {
println key
}
n.onKey keys, => {
println keys
}
var i I = n
i.onKey "1", key => {
println key
}
i.onKey ["1","2"], key => {
println key
}
`, `package main
import "fmt"
func main() {
n := &N[int]{}
n.OnKey__0("1", func() {
})
keys := []string{"1", "2"}
n.OnKey__3(keys, func(key string) {
fmt.Println(key)
})
n.OnKey__2(keys, func() {
fmt.Println(keys)
})
var i I = n
i.OnKey__1("1", func(key string) {
fmt.Println(key)
})
i.OnKey__3([]string{"1", "2"}, func(key string) {
fmt.Println(key)
})
}
`)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.18
require (
github.com/fsnotify/fsnotify v1.7.0
github.com/goplus/c2go v0.7.17
github.com/goplus/gox v1.13.1-0.20231224034658-01dc57167636
github.com/goplus/gox v1.13.1-0.20231225053549-a6c41ff21756
github.com/goplus/mod v0.11.10-0.20231210062211-b9032d0f7810
github.com/qiniu/x v1.13.2
golang.org/x/tools v0.16.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ github.com/goplus/gox v1.13.1-0.20231222052208-e6decd192e88 h1:AIEOfpJP+ES2A/kbI
github.com/goplus/gox v1.13.1-0.20231222052208-e6decd192e88/go.mod h1:iIchh0wp8Ye0DOPcFgHc5d0qlMOx8/OJ+DBQfe7hcTs=
github.com/goplus/gox v1.13.1-0.20231224034658-01dc57167636 h1:q7GIZuo3wAxPVjdnnjkxMlaf4wjMn5UdleoXbEJCUXY=
github.com/goplus/gox v1.13.1-0.20231224034658-01dc57167636/go.mod h1:iIchh0wp8Ye0DOPcFgHc5d0qlMOx8/OJ+DBQfe7hcTs=
github.com/goplus/gox v1.13.1-0.20231225053549-a6c41ff21756 h1:KkSgwZXFW5YbgCv++a0Bvzc+zKBR8SsSKo/9C1BkOjI=
github.com/goplus/gox v1.13.1-0.20231225053549-a6c41ff21756/go.mod h1:iIchh0wp8Ye0DOPcFgHc5d0qlMOx8/OJ+DBQfe7hcTs=
github.com/goplus/mod v0.11.9/go.mod h1:YxrBMhvWGcvLU14j8e7qyKSVnj5Loba7GgH1rNXJtDg=
github.com/goplus/mod v0.11.10-0.20231210062211-b9032d0f7810 h1:d+1SoTwaKrHwMp2EZPzZxV8VnqVr+QxXQCtz/zn+Tow=
github.com/goplus/mod v0.11.10-0.20231210062211-b9032d0f7810/go.mod h1:YxrBMhvWGcvLU14j8e7qyKSVnj5Loba7GgH1rNXJtDg=
Expand Down

0 comments on commit db2caf2

Please sign in to comment.