github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/go/analysis/passes/reflectvaluecompare/testdata/src/a/a.go (about) 1 // Copyright 2021 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 // This file contains tests for the reflectvaluecompare checker. 6 7 package a 8 9 import ( 10 "reflect" 11 ) 12 13 func f() { 14 var x, y reflect.Value 15 var a, b interface{} 16 _ = x == y // want `avoid using == with reflect.Value` 17 _ = x == a // want `avoid using == with reflect.Value` 18 _ = a == x // want `avoid using == with reflect.Value` 19 _ = a == b 20 21 // Comparing to reflect.Value{} is ok. 22 _ = a == reflect.Value{} 23 _ = reflect.Value{} == a 24 _ = reflect.Value{} == reflect.Value{} 25 } 26 func g() { 27 var x, y reflect.Value 28 var a, b interface{} 29 _ = x != y // want `avoid using != with reflect.Value` 30 _ = x != a // want `avoid using != with reflect.Value` 31 _ = a != x // want `avoid using != with reflect.Value` 32 _ = a != b 33 34 // Comparing to reflect.Value{} is ok. 35 _ = a != reflect.Value{} 36 _ = reflect.Value{} != a 37 _ = reflect.Value{} != reflect.Value{} 38 } 39 func h() { 40 var x, y reflect.Value 41 var a, b interface{} 42 reflect.DeepEqual(x, y) // want `avoid using reflect.DeepEqual with reflect.Value` 43 reflect.DeepEqual(x, a) // want `avoid using reflect.DeepEqual with reflect.Value` 44 reflect.DeepEqual(a, x) // want `avoid using reflect.DeepEqual with reflect.Value` 45 reflect.DeepEqual(a, b) 46 47 // Comparing to reflect.Value{} is ok. 48 reflect.DeepEqual(reflect.Value{}, a) 49 reflect.DeepEqual(a, reflect.Value{}) 50 reflect.DeepEqual(reflect.Value{}, reflect.Value{}) 51 }