aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2020-06-03 10:52:23 -0700
committerKeith Randall <khr@golang.org>2020-06-03 19:07:55 +0000
commit9984ef824c635421c225f5bf3d5573a1fbd94dde (patch)
treeec5c975c2c1c3161ef9e04e95d53246b633f4ebe /test
parent66e35c995bb68d62612644c6566f500c3df45026 (diff)
downloadgo-9984ef824c635421c225f5bf3d5573a1fbd94dde.tar.gz
go-9984ef824c635421c225f5bf3d5573a1fbd94dde.zip
cmd/compile: test that equality is evaluated in order
Make sure that we compare fields of structs and elements of arrays in order, with proper short-circuiting. Update #8606 Change-Id: I0a66ad92ea0af7bcc56dfdb275dec2b8d7e8b4fe Reviewed-on: https://go-review.googlesource.com/c/go/+/236147 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue8606.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/test/fixedbugs/issue8606.go b/test/fixedbugs/issue8606.go
new file mode 100644
index 0000000000..676c06c0b2
--- /dev/null
+++ b/test/fixedbugs/issue8606.go
@@ -0,0 +1,46 @@
+// run
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Check to make sure that we compare fields in order. See issue 8606.
+
+package main
+
+import "fmt"
+
+func main() {
+ type A [2]interface{}
+ type S struct{ x, y interface{} }
+
+ for _, test := range []struct {
+ panic bool
+ a, b interface{}
+ }{
+ {false, A{1, []byte{1}}, A{2, []byte{1}}},
+ {true, A{[]byte{1}, 1}, A{[]byte{1}, 2}},
+ {false, S{1, []byte{1}}, S{2, []byte{1}}},
+ {true, S{[]byte{1}, 1}, S{[]byte{1}, 2}},
+ } {
+ f := func() {
+ if test.a == test.b {
+ panic(fmt.Sprintf("values %#v and %#v should not be equal", test.a, test.b))
+ }
+ }
+ if test.panic {
+ shouldPanic(fmt.Sprintf("comparing %#v and %#v did not panic", test.a, test.b), f)
+ } else {
+ f() // should not panic
+ }
+ }
+}
+
+func shouldPanic(name string, f func()) {
+ defer func() {
+ if recover() == nil {
+ panic(name)
+ }
+ }()
+ f()
+}