blob: 1c5166ededf6d99d0a26cc22df78022235407c17 [file] [log] [blame]
Rémy Oudompheng2ece2f52012-02-18 22:15:42 +01001// run
Russ Cox46deaa22011-12-06 10:48:17 -05002
3// Copyright 2011 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
Rob Pike13514d42012-02-19 17:33:41 +11007// Test run-time error detection for interface values containing types
8// that cannot be compared for equality.
Russ Cox46deaa22011-12-06 10:48:17 -05009
10package main
11
12func main() {
13 cmp(1)
Russ Cox196b6632011-12-12 22:22:09 -050014
Russ Cox46deaa22011-12-06 10:48:17 -050015 var (
16 m map[int]int
Russ Cox196b6632011-12-12 22:22:09 -050017 s struct{ x []int }
Russ Cox46deaa22011-12-06 10:48:17 -050018 f func()
19 )
20 noCmp(m)
21 noCmp(s)
22 noCmp(f)
23}
24
25func cmp(x interface{}) bool {
26 return x == x
27}
28
29func noCmp(x interface{}) {
30 shouldPanic(func() { cmp(x) })
31}
32
33func shouldPanic(f func()) {
34 defer func() {
35 if recover() == nil {
36 panic("function should panic")
37 }
38 }()
39 f()
40}