-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Open
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)ProposalProposal-Accepted
Milestone
Description
This code doesn't do what you think it does:
func f(x, y reflect.Value) bool {
return reflect.DeepEqual(x, y)
}
It compares the internal details of the two reflect.Value
structs, not their contents. The correct code would be reflect.DeepEqual(x.Interface(), y.Interface())
.
I don't see any reason why you'd ever want to use DeepEqual
on a reflect.Value
. Hence no false positives.
If you really wanted to compare two reflect.Value
s (but you shouldn't), ==
is equivalent to DeepEqual
.
Seems like an easy mistake to make (see #43986 ). Not sure how common it might be, but I suspect it might be common enough to warrant a check.
bcmills, skuzzymiglet, dominikh, komuw, antichris and 5 more
Metadata
Metadata
Assignees
Labels
AnalysisIssues related to static analysis (vet, x/tools/go/analysis)Issues related to static analysis (vet, x/tools/go/analysis)ProposalProposal-Accepted
Type
Projects
Status
Accepted