MCPcopy Create free account
hub / github.com/google/go-cmp / apply

Method apply

cmp/options.go:221–252  ·  view source on GitHub ↗
(s *state, vx, vy reflect.Value)

Source from the content-addressed store, hash-verified

219 return nil
220}
221func (validator) apply(s *state, vx, vy reflect.Value) {
222 // Implies missing slice element or map entry.
223 if !vx.IsValid() || !vy.IsValid() {
224 s.report(vx.IsValid() == vy.IsValid(), 0)
225 return
226 }
227
228 // Unable to Interface implies unexported field without visibility access.
229 if !vx.CanInterface() || !vy.CanInterface() {
230 help := "consider using a custom Comparer; if you control the implementation of type, you can also consider using an Exporter, AllowUnexported, or cmpopts.IgnoreUnexported"
231 var name string
232 if t := s.curPath.Index(-2).Type(); t.Name() != "" {
233 // Named type with unexported fields.
234 name = fmt.Sprintf("%q.%v", t.PkgPath(), t.Name()) // e.g., "path/to/package".MyType
235 if _, ok := reflect.New(t).Interface().(error); ok {
236 help = "consider using cmpopts.EquateErrors to compare error values"
237 } else if t.Comparable() {
238 help = "consider using cmpopts.EquateComparable to compare comparable Go types"
239 }
240 } else {
241 // Unnamed type with unexported fields. Derive PkgPath from field.
242 var pkgPath string
243 for i := 0; i < t.NumField() && pkgPath == ""; i++ {
244 pkgPath = t.Field(i).PkgPath
245 }
246 name = fmt.Sprintf("%q.(%v)", pkgPath, t.String()) // e.g., "path/to/package".(struct { a int })
247 }
248 panic(fmt.Sprintf("cannot handle unexported field at %#v:\n\t%v\n%s", s.curPath, name, help))
249 }
250
251 panic("not reachable")
252}
253
254// identRx represents a valid identifier according to the Go specification.
255const identRx = `[_\p{L}][_\p{L}\p{N}]*`

Callers

nothing calls this directly

Calls 5

reportMethod · 0.80
TypeMethod · 0.65
StringMethod · 0.65
IndexMethod · 0.45
NameMethod · 0.45

Tested by

no test coverage detected