Skip to content

Commit

Permalink
TestOverloadNamed
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Jan 25, 2024
1 parent 946a877 commit d426825
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
67 changes: 67 additions & 0 deletions cl/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5140,3 +5140,70 @@ func main() {
}
`)
}

func TestOverloadNamed(t *testing.T) {
gopClTest(t, `
import "github.com/goplus/gop/cl/internal/overload/bar"
var a bar.Var[int]
var b bar.Var[bar.M]
c := bar.Var(string)
d := bar.Var(bar.M)
`, `package main
import "github.com/goplus/gop/cl/internal/overload/bar"
var a bar.Var__0[int]
var b bar.Var__1[map[string]any]
func main() {
c := bar.Gopx_Var_Cast__0[string]()
d := bar.Gopx_Var_Cast__1[map[string]any]()
}
`)
}

func TestMixedOverloadNamed(t *testing.T) {
gopMixedClTest(t, "main", `package main
const GopPackage = true
type M = map[string]any
type basetype interface {
string | int | bool | float64
}
type Var__0[T basetype] struct {
val T
}
type Var__1[T map[string]any] struct {
val T
}
func Gopx_Var_Cast__0[T basetype]() *Var__0[T] {
return new(Var__0[T])
}
func Gopx_Var_Cast__1[T map[string]any]() *Var__1[T] {
return new(Var__1[T])
}
`, `
var a Var[int]
var b Var[M]
c := Var(string)
d := Var(M)
`, `package main
var a Var__0[int]
var b Var__1[map[string]interface {
}]
func main() {
c := Gopx_Var_Cast__0[string]()
d := Gopx_Var_Cast__1[map[string]interface {
}]()
}
`)
}
33 changes: 33 additions & 0 deletions cl/internal/overload/bar/bar.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package bar

const GopPackage = true

type M = map[string]any

type basetype interface {
string | int | bool | float64
}

type Var__0[T basetype] struct {
val T
}

func (p *Var__0[T]) Value() T {
return p.val
}

type Var__1[T map[string]any] struct {
val T
}

func (p *Var__1[T]) Value() T {
return p.val
}

func Gopx_Var_Cast__0[T basetype]() *Var__0[T] {
return new(Var__0[T])
}

func Gopx_Var_Cast__1[T map[string]any]() *Var__1[T] {
return new(Var__1[T])
}

0 comments on commit d426825

Please sign in to comment.