Skip to content

Commit

Permalink
Merge pull request #1457 from visualfc/cl
Browse files Browse the repository at this point in the history
cl: fix compileCallArgs recover check
  • Loading branch information
xushiwei authored Oct 8, 2023
2 parents 3adfa80 + 48dff3d commit 95c4e6a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cl/error_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -964,3 +964,9 @@ const b = -1
a := uint128(b)
`)
}

func TestErrCompileFunc(t *testing.T) {
codeErrorTest(t, `./bar.gop:2:1: compile func printf("%+v\n", int32) error: unreachable`, `
printf("%+v\n", int32)
`)
}
9 changes: 7 additions & 2 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,13 @@ func compileCallExpr(ctx *blockCtx, v *ast.CallExpr, inFlags int) {
func compileCallArgs(fn *fnType, fnt types.Type, ctx *blockCtx, v *ast.CallExpr, ellipsis bool, flags gox.InstrFlags) (err error) {
n := ctx.cb.InternalStack().Len()
defer func() {
if v := recover(); v != nil {
err = v.(error)
if r := recover(); r != nil {
if e, ok := r.(error); ok {
err = e
} else {
src, pos := ctx.LoadExpr(v)
err = newCodeErrorf(&pos, "compile func %v error: %v", src, r)
}
ctx.cb.InternalStack().SetLen(n)
}
}()
Expand Down

0 comments on commit 95c4e6a

Please sign in to comment.