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

Method callTTBFunc

cmp/compare.go:347–364  ·  view source on GitHub ↗
(f, x, y reflect.Value)

Source from the content-addressed store, hash-verified

345}
346
347func (s *state) callTTBFunc(f, x, y reflect.Value) bool {
348 if !s.dynChecker.Next() {
349 return f.Call([]reflect.Value{x, y})[0].Bool()
350 }
351
352 // Swapping the input arguments is sufficient to check that
353 // f is symmetric and deterministic.
354 // We run in goroutines so that the race detector (if enabled) can detect
355 // unsafe mutations to the input.
356 c := make(chan reflect.Value)
357 go detectRaces(c, f, y, x)
358 got := <-c
359 want := f.Call([]reflect.Value{x, y})[0].Bool()
360 if !got.IsValid() || got.Bool() != want {
361 panic(fmt.Sprintf("non-deterministic or non-symmetric function detected: %s", function.NameOf(f)))
362 }
363 return want
364}
365
366func detectRaces(c chan<- reflect.Value, f reflect.Value, vs ...reflect.Value) {
367 var ret reflect.Value

Callers 3

tryMethodMethod · 0.95
filterMethod · 0.80
applyMethod · 0.80

Calls 3

NameOfFunction · 0.92
detectRacesFunction · 0.85
NextMethod · 0.80

Tested by

no test coverage detected