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
cmd/compile: generic types implementing fmt.Stringer crash fmt.Printf #47740
Comments
Here's a simpler reproducer for at least one of the issues at play here:
I get this error:
|
actually, that's neither of the original issues - it's just crashing the compiler |
FWIW, the code I posted seems to work with Larger piece of code that works with |
CC @mdempsky since the above ICE is in the IR (though seems like it also leads to a miscompile?), and seems to be fixed with |
Also cc @danscales @randall77 |
Change https://golang.org/cl/342989 mentions this issue: |
At tip (a304273) with
-gcflags='-G=3'
.I have seen a strange behavior with generics types that implement interfaces such as
fmt.Stringer
. The errors happen at runtime, and greatly differ based on the specific example. Even modifying a few characters in the source code makes the specific panic different, or it makes it go away completely.Here is one such example. I have managed to reproduce this with a smaller code example, but that was with an older version of the Go tree. As I said -- this is very twitchy and inconsistent.
The code currently panics with
Notice that it dies only in the second call to fmt.Printf. The first call prints something about a panic, but doesn't actually crash the program, it's recovered.
A workaround for this issue is to manually call the
String()
method on the type. Of course this is feasible because it makes sense forfmt.Stringer
, the workaround might not be feasible with other interface.This is so twitchy that even inlining
e1
inside the call tofmt.Printf
makes the crash recoverable (but the output is still garbage).I can't reproduce it any more, but with a previous version of the Go tree, the panic output said something about a possible linker bug.
I have not been able to reproduce this problem with go2go: https://go2goplay.golang.org/p/IOA2krkbxeZ
The text was updated successfully, but these errors were encountered: