Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cl: loadVars check recover #1372

Merged
merged 3 commits into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cl/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,14 @@ func loadVars(ctx *blockCtx, v *ast.ValueSpec, global bool) {
varDecl := ctx.pkg.NewVarEx(scope, v.Names[0].Pos(), typ, names...)
if nv := len(v.Values); nv > 0 {
cb := varDecl.InitStart(ctx.pkg)
if enableRecover {
defer func() {
if e := recover(); e != nil {
cb.ResetInit()
panic(e)
}
}()
}
if nv == 1 && len(names) == 2 {
compileExpr(ctx, v.Values[0], clCallWithTwoValue)
} else {
Expand Down
15 changes: 15 additions & 0 deletions cl/error_msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -866,3 +866,18 @@ import (
)
`)
}

func TestErrVarInFunc(t *testing.T) {
codeErrorTest(t, `./bar.gop:6:10: too few arguments in call to set("box")
have (untyped string)
want (name string, v int)
./bar.gop:7:10: undefined: a`, `
func set(name string, v int) string {
return name
}
func test() {
var a = set("box")
println(a)
}
`)
}