Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Analyzers do not set ResultType #76

Open
uhthomas opened this issue May 28, 2022 · 1 comment · May be fixed by #77
Open

Analyzers do not set ResultType #76

uhthomas opened this issue May 28, 2022 · 1 comment · May be fixed by #77

Comments

@uhthomas
Copy link

According to https://pkg.go.dev/golang.org/x/tools/go/analysis#Analyzer:

type Analyzer struct {
	// ...

	// Run applies the analyzer to a package.
	// It returns an error if the analyzer failed.
	//
	// On success, the Run function may return a result
	// computed by the Analyzer; its type must match ResultType.
	// The driver makes this result available as an input to
	// another Analyzer that depends directly on this one (see
	// Requires) when it analyzes the same package.
	//
	// To pass analysis results between packages (and thus
	// potentially between address spaces), use Facts, which are
	// serializable.
	Run func(*[Pass](https://pkg.go.dev/golang.org/x/tools/go/analysis#Pass)) (interface{}, [error](https://pkg.go.dev/builtin#error))

	// ...

	// ResultType is the type of the optional result of the Run function.
	ResultType [reflect](https://pkg.go.dev/reflect).[Type](https://pkg.go.dev/reflect#Type)

	// ...
}

Because of this, the analyzers fail to run:

analyzer "command_injection" failed: internal error: on package github.com/jcmturner/gokrb5/v8/iana, analyzer command_injection returned a result of type []util.Finding, but declared ResultType <nil>
hxtk added a commit to hxtk/gokart that referenced this issue Jul 30, 2022
This change declares each of the analyzers in the analyzers
package to have a result type of
`[]github.com/praetorian-inc/gokart/util.Finding`.

A test has also been included that runs a minimal `*analysis.Pass`
through each analyzer's `Run` function, reflectively determines the
type of the result value, and compares it to the declared result type
of the analyzer.

Resolves praetorian-inc#76.
@hxtk hxtk linked a pull request Jul 30, 2022 that will close this issue
@hxtk
Copy link

hxtk commented Jul 30, 2022

This issue affected me as well when I tried to create wrappers for the analyzers for use with nogo from Bazel's rules_go.

I've created a pull request to upstream the patch that I ended up using in my repository, as well as add some tests to validate the functionality.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants