Commit 64627b04 authored by Russ Cox's avatar Russ Cox

check for type equality in deepequal

R=r,dnadasi
DELTA=9  (8 added, 0 deleted, 1 changed)
OCL=27473
CL=27486
parent 19692bee
......@@ -310,7 +310,7 @@ func TestInterfaceValue(t *testing.T) {
assert(v2.Type().String(), "interface { }");
v3 := v2.(reflect.InterfaceValue).Value();
assert(v3.Type().String(), "float");
i3 := v2.Interface();
if f, ok := i3.(float); !ok {
a, typ, c := sys.Reflect(i3);
......@@ -387,6 +387,8 @@ type Basic struct {
y float32
}
type NotBasic Basic
type Recursive struct {
x int;
r *Recursive
......@@ -429,6 +431,7 @@ var deepEqualTests = []DeepEqualTest {
DeepEqualTest{ 0.5, "hello", false },
DeepEqualTest{ []int{ 1, 2, 3 }, [3]int{ 1, 2, 3 }, false },
DeepEqualTest{ &[3]interface{} { 1, 2, 4 }, &[3]interface{} { 1, 2, "s" }, false },
DeepEqualTest{ Basic{ 1, 0.5 }, NotBasic{ 1, 0.5 }, false },
}
func TestDeepEqual(t *testing.T) {
......
......@@ -74,5 +74,10 @@ func deepValueEqual(v1, v2 Value, visited map[Addr]Addr) bool {
// handles recursive types. Until reflection supports maps, maps are equal iff
// they are identical.
func DeepEqual(a1, a2 interface{}) bool {
return deepValueEqual(NewValue(a1), NewValue(a2), make(map[Addr]Addr));
v1 := NewValue(a1);
v2 := NewValue(a2);
if !equalType(v1.Type(), v2.Type()) {
return false;
}
return deepValueEqual(v1, v2, make(map[Addr]Addr));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment