Skip to content

Incorrect recovery from double-panic #1126

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

Open
nevkontakte opened this issue Jul 17, 2022 · 0 comments
Open

Incorrect recovery from double-panic #1126

nevkontakte opened this issue Jul 17, 2022 · 0 comments
Assignees
Labels

Comments

@nevkontakte
Copy link
Member

Consider the following code:

package main

import "fmt"

func main() {
	defer func() { fmt.Println(recover()) }()
	defer func() { fmt.Println(recover()) }()
	defer panic(2)
	panic(1)
}

When executed by go:

$ go run main3.go
2
<nil>

When executed by GopherJS:

$ gopherjs run main3.go
2
1

Note that in the upstream implementation the later panic overrides the earlier panic, and only one call to recover() is necessary. However, GopherJS requires a separate call to recover from each panic. While go spec isn't explicit about it, it doesn't say that there is some kind of stack of panics. Instead it only defines two states or "panicing" and "not panicing" and a successful recover() call clears the state of panicing and resumes normal execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant