Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update gox support interface overload method #1592

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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