Skip to content

defer recover() should not actually recover. #1127

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 · 1 comment
Open

defer recover() should not actually recover. #1127

nevkontakte opened this issue Jul 17, 2022 · 1 comment
Assignees
Labels

Comments

@nevkontakte
Copy link
Member

Consider the following program:

package main

func main() {
	defer recover()
	panic(1)
}

Compare upstream vs gopherjs:

$ go run main.go
panic: 1

goroutine 1 [running]:
main.main()
        /home/aleks/git/repro/035-defer-recover/main.go:5 +0x65
exit status 2
$ gopherjs run main.go
# No errors

While this may seem counter-intuitive, this is WAI according to golang/go#1272.

@nevkontakte nevkontakte added this to the Go spec compliance milestone Jul 17, 2022
@nevkontakte nevkontakte self-assigned this Jul 17, 2022
@nevkontakte
Copy link
Member Author

This is likely because gopherjs wraps builtin deferrals into a proxy anonymous function, which makes it appear that recover() function is called from a deferred function, rather than being deferred itself. We can probably address this by decrementing $stackDepthOffset inside the proxy function.

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