Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
spec: clarify timing of nil-checks for defer/go statements #38634
Test program: https://play.golang.org/p/rDWCdf_ha5w
This program tests various conditions where a deferred function call can panic "early" (i.e., at the time of the defer statement) or "late" (i.e., at the time the deferred function is actually invoked).
When compiled with cmd/compile, it prints "early late early \\ early late early \\ late".
When compiled with gccgo (edit: 8.0), it prints "late late early \\ late late early \\" and then crashes with a fatal error. (Edit: gccgo 10.0.1 prints "late late early \\ late late early \\ late".)
I think cases 2, 3, 5, and 6 where cmd/compile and gccgo agree are correctly implemented.
I think gccgo is wrong to fatally error on case 7. (If for no reason other than because the fatal error says "go of nil func value", but it's a defer statement.)
I'm unsure about cases 1, 4, and 7 otherwise though. I suspect they should all be "early" or all be "late" though.
With a relatively new version of gccgo, this program will not crash. My gccgo version:
But the print result is still "late late early \ late late early \".