Proposal Details
The reflect.DeepEqual function is simple, and people often use it in tests in preference to more complex packages like github.com/google/go-cmp/cmp. But this can be misleading, and leads to issues like #43986 and #71702.
I propose that we add a vet check warning about uses of reflect.DeepEqual with values of types that are 1) imported; 2) contain references to unexported fields. Those are cases where reflect.DeepEqual is testing the internal state of a type defined in a different package, which means that the call is subject to breaking if the other package changes the type definition.
I believe that this meets vet's requirements for correctness and precision. However, I don't know how frequent the problem is.
I note that there is already a check in vet that warns about uses of reflect.DeepEqual specifically for the type reflect.Value (though I don't know how to actually run that check; it's not part of standard vet). This more general check could perhaps subsume that one.
CC @golang/tools-team
Proposal Details
The
reflect.DeepEqualfunction is simple, and people often use it in tests in preference to more complex packages like github.com/google/go-cmp/cmp. But this can be misleading, and leads to issues like #43986 and #71702.I propose that we add a vet check warning about uses of
reflect.DeepEqualwith values of types that are 1) imported; 2) contain references to unexported fields. Those are cases wherereflect.DeepEqualis testing the internal state of a type defined in a different package, which means that the call is subject to breaking if the other package changes the type definition.I believe that this meets vet's requirements for correctness and precision. However, I don't know how frequent the problem is.
I note that there is already a check in vet that warns about uses of
reflect.DeepEqualspecifically for the typereflect.Value(though I don't know how to actually run that check; it's not part of standard vet). This more general check could perhaps subsume that one.CC @golang/tools-team