mirror of
https://github.com/golang/go
synced 2024-11-23 18:50:05 -07:00
f72d7cfc8f
Add interfaces which differ in type. Those used so far only differ in value, not type. These additional tests are needed to generate a failure before CL 236278 went in. Update #8606 Change-Id: Icdb7647b1973c2fff7e5afe2bd8b8c1b384f583e Reviewed-on: https://go-review.googlesource.com/c/go/+/236418 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
// 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}},
|
|
{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()
|
|
}
|