Skip to content

Commit

Permalink
Merge pull request #1991 from visualfc/overload_options
Browse files Browse the repository at this point in the history
cl: fix compileCallArgs recover error for overloads
  • Loading branch information
xushiwei authored Oct 19, 2024
2 parents c3f9784 + b65a745 commit 215ee54
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions cl/compile_gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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})
}
`)
}
6 changes: 6 additions & 0 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 215ee54

Please sign in to comment.