Skip to content

Commit 8dd9212

Browse files
authored
Merge pull request #1833 from luoliwoshang/cl-overload
update:correct anonymous overloaded function naming
2 parents 9875bae + 1ec9246 commit 8dd9212

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

cl/compile.go

+1
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,7 @@ func preloadFile(p *gogen.Package, ctx *blockCtx, f *ast.File, goFile string, ge
10881088
case *ast.FuncLit:
10891089
checkOverloadFunc(d)
10901090
name1 := overloadFuncName(name.Name, idx)
1091+
onames = append(onames, "") // const Gopo_xxx = "xxxInt,,xxxFloat"
10911092
ctx.lbinames = append(ctx.lbinames, name1)
10921093
preloadFuncDecl(&ast.FuncDecl{
10931094
Doc: d.Doc,

cl/compile_gop_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,46 @@ func main() {
376376
`)
377377
}
378378

379+
func TestOverloadFunc3(t *testing.T) {
380+
gopClTest(t, `
381+
func addInt(a, b int) int {
382+
return a + b
383+
}
384+
385+
func addFloat(a, b float64) float64 {
386+
return a * b
387+
}
388+
389+
func add = (
390+
func (a,b string) string { return a + b }
391+
addInt
392+
addFloat
393+
)
394+
395+
println add(100, 7)
396+
println add(1.2, 3.14)
397+
`, `package main
398+
399+
import "fmt"
400+
401+
const Gopo_add = ",addInt,addFloat"
402+
403+
func add__0(a string, b string) string {
404+
return a + b
405+
}
406+
func addInt(a int, b int) int {
407+
return a + b
408+
}
409+
func addFloat(a float64, b float64) float64 {
410+
return a * b
411+
}
412+
func main() {
413+
fmt.Println(addInt(100, 7))
414+
fmt.Println(addFloat(1.2, 3.14))
415+
}
416+
`)
417+
}
418+
379419
func TestOverload(t *testing.T) {
380420
gopClTest(t, `
381421
import "github.com/goplus/gop/cl/internal/overload/foo"

0 commit comments

Comments
 (0)