lundi 16 septembre 2019

go-cmp when comparing 2 structs treats empty interface value as int and flat64

So I am using go-cmp github.com/google/go-cmp/cmp. To compare 2 structs. Both the structs are of same type. When comparing the result I am seeing the following difference.

I am using go v1.12

type Sample map[string]interface
var a Sample
var b Sample

cmp.Diff(a,b)


// Somewhere in code I do this
a["sample"] = 1 // this is optional.

So if I compare a and b I see the diff where it interprets the same field as int(0) and float64(0)

-: int(0)
+: float64(0)

I expect the diff to be nil





Aucun commentaire:

Enregistrer un commentaire