diff options
author | Russ Cox <rsc@golang.org> | 2011-12-06 10:48:17 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-12-06 10:48:17 -0500 |
commit | 46deaa297bcf76438ae17b070ef351d5b91d3d59 (patch) | |
tree | e38a1c832c6501c507a96e998c6e87d3716fd068 /test/interface | |
parent | e4e4cdb39a821eb850200967cb21ab36e8d3a1be (diff) | |
download | go-46deaa297bcf76438ae17b070ef351d5b91d3d59.tar.gz go-46deaa297bcf76438ae17b070ef351d5b91d3d59.zip |
gc: disallow map/func equality via interface comparison
Missed when I removed direct map/func equality.
R=ken2
CC=golang-dev
https://golang.org/cl/5452052
Diffstat (limited to 'test/interface')
-rw-r--r-- | test/interface/noeq.go | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/interface/noeq.go b/test/interface/noeq.go new file mode 100644 index 0000000000..be368218d7 --- /dev/null +++ b/test/interface/noeq.go @@ -0,0 +1,39 @@ +// $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG: interface/noeq + +// Copyright 2011 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. + +// Interface values containing types that cannot be compared for equality. + +package main + +func main() { + cmp(1) + + var ( + m map[int]int + s struct{} + f func() + ) + noCmp(m) + noCmp(s) + noCmp(f) +} + +func cmp(x interface{}) bool { + return x == x +} + +func noCmp(x interface{}) { + shouldPanic(func() { cmp(x) }) +} + +func shouldPanic(f func()) { + defer func() { + if recover() == nil { + panic("function should panic") + } + }() + f() +} |