return -1; // needs special compare
case TSTRUCT:
- if(t->type != T && t->type->down == T) {
+ if(t->type != T && t->type->down == T && !isblanksym(t->type->sym)) {
// One-field struct is same as that one field alone.
return algtype1(t->type->type, bad);
}
ret = AMEM;
for(t1=t->type; t1!=T; t1=t1->down) {
- // Blank fields and padding must be ignored,
- // so need special compare.
- if(isblanksym(t1->sym) || ispaddedfield(t1, t->width)) {
+ // All fields must be comparable.
+ a = algtype1(t1->type, bad);
+ if(a == ANOEQ)
+ return ANOEQ;
+
+ // Blank fields, padded fields, fields with non-memory
+ // equality need special compare.
+ if(a != AMEM || isblanksym(t1->sym) || ispaddedfield(t1, t->width)) {
ret = -1;
continue;
}
- a = algtype1(t1->type, bad);
- if(a == ANOEQ)
- return ANOEQ; // not comparable
- if(a != AMEM)
- ret = -1; // needs special compare
}
return ret;
}
func (T) _() {
}
+type U struct {
+ _ struct{ a, b, c int }
+}
+
const (
c0 = iota
_
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)
_ 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"
}
// 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
--- /dev/null
+// 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"