aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/testdata
diff options
context:
space:
mode:
authorhopehook <hopehook.com@gmail.com>2022-04-12 17:46:36 +0800
committerGopher Robot <gobot@golang.org>2022-04-15 01:08:38 +0000
commit5a4f0b6f1e6d3c022ee30884590526ab7d3f580b (patch)
tree65ed5695981923bf38fc2c9fd56d9804e1798d5e /src/runtime/testdata
parent78bea702cd38ac5004a97f110e7f659336a04d57 (diff)
downloadgo-5a4f0b6f1e6d3c022ee30884590526ab7d3f580b.tar.xz
runtime: don't discard value from panic while panicking
In issue #17671, there are a endless loop if printing the panic value panics, CL 30358 has fixed that. As issue #52257 pointed out, above change should not discard the value from panic while panicking. With this CL, when we recover from a panic in error.Error() or stringer.String(), and the recovered value is string, then we can print it normally. Fixes #52257 Change-Id: Icfcc4a1a390635de405eea04904b4607ae9e3055 Reviewed-on: https://go-review.googlesource.com/c/go/+/399874 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Diffstat (limited to 'src/runtime/testdata')
-rw-r--r--src/runtime/testdata/testprog/crash.go73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/runtime/testdata/testprog/crash.go b/src/runtime/testdata/testprog/crash.go
index c4990cdda9..a2294ba149 100644
--- a/src/runtime/testdata/testprog/crash.go
+++ b/src/runtime/testdata/testprog/crash.go
@@ -12,6 +12,13 @@ import (
func init() {
register("Crash", Crash)
register("DoublePanic", DoublePanic)
+ register("ErrorPanic", ErrorPanic)
+ register("StringerPanic", StringerPanic)
+ register("DoubleErrorPanic", DoubleErrorPanic)
+ register("DoubleStringerPanic", DoubleStringerPanic)
+ register("StringPanic", StringPanic)
+ register("NilPanic", NilPanic)
+ register("CircularPanic", CircularPanic)
}
func test(name string) {
@@ -64,3 +71,69 @@ func DoublePanic() {
}()
panic(P("XXX"))
}
+
+// Test that panic while panicking discards error message
+// See issue 52257
+type exampleError struct{}
+
+func (e exampleError) Error() string {
+ panic("important error message")
+}
+
+func ErrorPanic() {
+ panic(exampleError{})
+}
+
+type examplePanicError struct{}
+
+func (e examplePanicError) Error() string {
+ panic(exampleError{})
+}
+
+func DoubleErrorPanic() {
+ panic(examplePanicError{})
+}
+
+type exampleStringer struct{}
+
+func (s exampleStringer) String() string {
+ panic("important stringer message")
+}
+
+func StringerPanic() {
+ panic(exampleStringer{})
+}
+
+type examplePanicStringer struct{}
+
+func (s examplePanicStringer) String() string {
+ panic(exampleStringer{})
+}
+
+func DoubleStringerPanic() {
+ panic(examplePanicStringer{})
+}
+
+func StringPanic() {
+ panic("important string message")
+}
+
+func NilPanic() {
+ panic(nil)
+}
+
+type exampleCircleStartError struct {}
+
+func (e exampleCircleStartError) Error() string {
+ panic(exampleCircleEndError{})
+}
+
+type exampleCircleEndError struct {}
+
+func (e exampleCircleEndError) Error() string {
+ panic(exampleCircleStartError{})
+}
+
+func CircularPanic() {
+ panic(exampleCircleStartError{})
+} \ No newline at end of file