| 1 | // Copyright 2023 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | // Package reflectvaluecompare defines an Analyzer that checks for accidentally |
| 6 | // using == or reflect.DeepEqual to compare reflect.Value values. |
| 7 | // See issues 43993 and 18871. |
| 8 | // |
| 9 | // # Analyzer reflectvaluecompare |
| 10 | // |
| 11 | // reflectvaluecompare: check for comparing reflect.Value values with == or reflect.DeepEqual |
| 12 | // |
| 13 | // The reflectvaluecompare checker looks for expressions of the form: |
| 14 | // |
| 15 | // v1 == v2 |
| 16 | // v1 != v2 |
| 17 | // reflect.DeepEqual(v1, v2) |
| 18 | // |
| 19 | // where v1 or v2 are reflect.Values. Comparing reflect.Values directly |
| 20 | // is almost certainly not correct, as it compares the reflect package's |
| 21 | // internal representation, not the underlying value. |
| 22 | // Likely what is intended is: |
| 23 | // |
| 24 | // v1.Interface() == v2.Interface() |
| 25 | // v1.Interface() != v2.Interface() |
| 26 | // reflect.DeepEqual(v1.Interface(), v2.Interface()) |
| 27 | package reflectvaluecompare |