diff options
author | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2013-07-02 09:08:43 +0200 |
---|---|---|
committer | R?my Oudompheng <oudomphe@phare.normalesup.org> | 2013-07-02 09:08:43 +0200 |
commit | ad500041ea3b0e6c9dbb63035f8aa2d219520713 (patch) | |
tree | 48474c9115b4a26892e096413bd7d51ed6c71ebd /test | |
parent | 23f1ec666073f3d4f013bb03c5d65ba1a39e1d4b (diff) | |
download | go-ad500041ea3b0e6c9dbb63035f8aa2d219520713.tar.gz |
cmd/gc: fix computation of equality class of types.
A struct with a single field was considered as equivalent to the
field type, which is incorrect is the field is blank.
Fields with padding could make the compiler think some
types are comparable when they are not.
Fixes issue 5698.
R=rsc, golang-dev, daniel.morsing, bradfitz, gri, r
CC=golang-dev
https://codereview.appspot.com/10271046
Diffstat (limited to 'test')
-rw-r--r-- | test/blank.go | 11 | ||||
-rw-r--r-- | test/blank1.go | 7 | ||||
-rw-r--r-- | test/cmp.go | 2 | ||||
-rw-r--r-- | test/cmp6.go | 2 | ||||
-rw-r--r-- | test/fixedbugs/issue5698.go | 18 |
5 files changed, 38 insertions, 2 deletions
diff --git a/test/blank.go b/test/blank.go index 7f7d9f6f7..46b61559d 100644 --- a/test/blank.go +++ b/test/blank.go @@ -27,6 +27,10 @@ func (T) _() { func (T) _() { } +type U struct { + _ struct{ a, b, c int } +} + const ( c0 = iota _ @@ -116,6 +120,13 @@ func main() { if t1 != t2 { panic("T{} != T{}") } + + var u1, u2 interface{} + u1 = *(*U)(unsafe.Pointer(&T1{1, 2, 3})) + u2 = *(*U)(unsafe.Pointer(&T1{4, 5, 6})) + if u1 != u2 { + panic("U{} != U{}") + } } h(a, b) diff --git a/test/blank1.go b/test/blank1.go index 4edb2db70..f46a50051 100644 --- a/test/blank1.go +++ b/test/blank1.go @@ -13,9 +13,16 @@ var t struct { _ int } +type T struct { + _ []int +} + func main() { _() // ERROR "cannot use _ as value" x := _+1 // ERROR "cannot use _ as value" _ = x _ = t._ // ERROR "cannot refer to blank field" + + var v1, v2 T + _ = v1 == v2 // ERROR "cannot be compared|non-comparable" } diff --git a/test/cmp.go b/test/cmp.go index 5be64561d..7183f0207 100644 --- a/test/cmp.go +++ b/test/cmp.go @@ -296,7 +296,7 @@ func main() { { var x = struct { x int - _ []int + _ string y float64 _ float64 z int diff --git a/test/cmp6.go b/test/cmp6.go index 7d99aae18..839c274bc 100644 --- a/test/cmp6.go +++ b/test/cmp6.go @@ -53,7 +53,7 @@ func main() { // Comparison of structs should have a good message use(t3 == t3) // ERROR "struct|expected" - use(t4 == t4) // ok; the []int is a blank field + use(t4 == t4) // ERROR "cannot be compared|non-comparable" // Slices, functions, and maps too. var x []int diff --git a/test/fixedbugs/issue5698.go b/test/fixedbugs/issue5698.go new file mode 100644 index 000000000..035bbd35d --- /dev/null +++ b/test/fixedbugs/issue5698.go @@ -0,0 +1,18 @@ +// errorcheck + +// Copyright 2013 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. + +// Issue 5698: can define a key type with slices. + +package main + +type Key struct { + a int16 // the compiler was confused by the padding. + b []int +} + +type Val struct{} + +type Map map[Key]Val // ERROR "invalid map key type" |