MCPcopy
hub / github.com/google/go-cmp / rootStep

Function rootStep

cmp/compare.go:141–165  ·  cmp/compare.go::rootStep

rootStep constructs the first path step. If x and y have differing types, then they are stored within an empty interface type.

(x, y interface{})

Source from the content-addressed store, hash-verified

139// rootStep constructs the first path step. If x and y have differing types,
140// then they are stored within an empty interface type.
141func rootStep(x, y interface{}) PathStep {
142 vx := reflect.ValueOf(x)
143 vy := reflect.ValueOf(y)
144
145 // If the inputs are different types, auto-wrap them in an empty interface
146 // so that they have the same parent type.
147 var t reflect.Type
148 if !vx.IsValid() || !vy.IsValid() || vx.Type() != vy.Type() {
149 t = anyType
150 if vx.IsValid() {
151 vvx := reflect.New(t).Elem()
152 vvx.Set(vx)
153 vx = vvx
154 }
155 if vy.IsValid() {
156 vvy := reflect.New(t).Elem()
157 vvy.Set(vy)
158 vy = vvy
159 }
160 } else {
161 t = vx.Type()
162 }
163
164 return &pathStep{t, vx, vy}
165}
166
167type state struct {
168 // These fields represent the "comparison state".

Callers 2

EqualFunction · 0.85
DiffFunction · 0.85

Calls 1

TypeMethod · 0.65

Tested by

no test coverage detected