From b65a7450338aa3bf9929a39c7129550f2c0a7e7c Mon Sep 17 00:00:00 2001 From: visualfc Date: Fri, 11 Oct 2024 11:08:19 +0800 Subject: [PATCH] cl: fix compileCallArgs recover error for overloads --- cl/compile_gop_test.go | 27 +++++++++++++++++++++++++++ cl/expr.go | 6 ++++++ 2 files changed, 33 insertions(+) diff --git a/cl/compile_gop_test.go b/cl/compile_gop_test.go index 73874dfee..be836b389 100644 --- a/cl/compile_gop_test.go +++ b/cl/compile_gop_test.go @@ -1570,3 +1570,30 @@ func main() { } `) } + +func TestOverlodOptions(t *testing.T) { + gopMixedClTest(t, "main", ` +package main + +type PlayOptions struct { + Action int + Wait bool + Loop bool +} +type Game struct { +} +func (g *Game) Play__0(options *PlayOptions) { +} +func (g *Game) Play__1(name string, options *PlayOptions) { +} +`, ` +g := &Game{} +g.play "work", { Action: 0, Loop: true } +`, `package main + +func main() { + g := &Game{} + g.Play__1("work", &PlayOptions{Action: 0, Loop: true}) +} +`) +} diff --git a/cl/expr.go b/cl/expr.go index 7b76ede18..dec29bf9b 100644 --- a/cl/expr.go +++ b/cl/expr.go @@ -753,6 +753,12 @@ func fnCall(ctx *blockCtx, v *ast.CallExpr, flags gogen.InstrFlags, extra int) e } func compileCallArgs(ctx *blockCtx, pfn *gogen.Element, fn *fnType, v *ast.CallExpr, ellipsis bool, flags gogen.InstrFlags) (err error) { + defer func() { + r := recover() + if r != nil { + err = ctx.recoverErr(r, v) + } + }() var needInferFunc bool for i, arg := range v.Args { switch expr := arg.(type) {