GoPLS Viewer

Home|gopls/go/analysis/passes/reflectvaluecompare/testdata/src/a/a.go
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
7package a
8
9import (
10    "reflect"
11)
12
13func f() {
14    var xy reflect.Value
15    var ab 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}
26func g() {
27    var xy reflect.Value
28    var ab 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}
39func h() {
40    var xy reflect.Value
41    var ab interface{}
42    reflect.DeepEqual(xy// want `avoid using reflect.DeepEqual with reflect.Value`
43    reflect.DeepEqual(xa// want `avoid using reflect.DeepEqual with reflect.Value`
44    reflect.DeepEqual(ax// want `avoid using reflect.DeepEqual with reflect.Value`
45    reflect.DeepEqual(ab)
46
47    // Comparing to reflect.Value{} is ok.
48    reflect.DeepEqual(reflect.Value{}, a)
49    reflect.DeepEqual(areflect.Value{})
50    reflect.DeepEqual(reflect.Value{}, reflect.Value{})
51}
52
MembersX
reflect
f
h
f.x
f.y
g
g.x
g.y
h.x
h.y
Members
X