reflectvaluecompare

package
v0.0.0-...-395a15b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package reflectvaluecompare defines an Analyzer that checks for accidentally using == or reflect.DeepEqual to compare reflect.Value values. See issues 43993 and 18871.

Analyzer reflectvaluecompare

reflectvaluecompare: check for comparing reflect.Value values with == or reflect.DeepEqual

The reflectvaluecompare checker looks for expressions of the form:

v1 == v2
v1 != v2
reflect.DeepEqual(v1, v2)

where v1 or v2 are reflect.Values. Comparing reflect.Values directly is almost certainly not correct, as it compares the reflect package's core representation, not the underlying value. Likely what is intended is:

v1.Interface() == v2.Interface()
v1.Interface() != v2.Interface()
reflect.DeepEqual(v1.Interface(), v2.Interface())

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = &analysis.Analyzer{
	Name:     "reflectvaluecompare",
	Doc:      analysisutil.MustExtractDoc(doc, "reflectvaluecompare"),
	URL:      "https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/reflectvaluecompare",
	Requires: []*analysis.Analyzer{inspect.Analyzer},
	Run:      run,
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL