compiler: Don't compare structs with blank non-comparable fields.
From-SVN: r205937
This commit is contained in:
parent
f7685b6677
commit
10d91e5798
|
@ -575,9 +575,6 @@ Type::are_compatible_for_comparison(bool is_equality_op, const Type *t1,
|
||||||
p != fields->end();
|
p != fields->end();
|
||||||
++p)
|
++p)
|
||||||
{
|
{
|
||||||
if (Gogo::is_sink_name(p->field_name()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!p->type()->is_comparable())
|
if (!p->type()->is_comparable())
|
||||||
{
|
{
|
||||||
if (reason != NULL)
|
if (reason != NULL)
|
||||||
|
|
|
@ -43,8 +43,8 @@ func main() {
|
||||||
var d string = "hel" // try to get different pointer
|
var d string = "hel" // try to get different pointer
|
||||||
d = d + "lo"
|
d = d + "lo"
|
||||||
|
|
||||||
// exp/ssa/interp can't handle unsafe.Pointer.
|
// go.tools/ssa/interp can't handle unsafe.Pointer.
|
||||||
if os.Getenv("GOSSAINTERP") != "" {
|
if os.Getenv("GOSSAINTERP") == "" {
|
||||||
if stringptr(c) == stringptr(d) {
|
if stringptr(c) == stringptr(d) {
|
||||||
panic("compiler too smart -- got same string")
|
panic("compiler too smart -- got same string")
|
||||||
}
|
}
|
||||||
|
@ -296,7 +296,7 @@ func main() {
|
||||||
{
|
{
|
||||||
var x = struct {
|
var x = struct {
|
||||||
x int
|
x int
|
||||||
_ []int
|
_ string
|
||||||
y float64
|
y float64
|
||||||
_ float64
|
_ float64
|
||||||
z int
|
z int
|
||||||
|
|
|
@ -53,7 +53,7 @@ func main() {
|
||||||
|
|
||||||
// Comparison of structs should have a good message
|
// Comparison of structs should have a good message
|
||||||
use(t3 == t3) // ERROR "struct|expected"
|
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.
|
// Slices, functions, and maps too.
|
||||||
var x []int
|
var x []int
|
||||||
|
|
Loading…
Reference in New Issue