Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Embedded interfaces are hard to ignore #29

Open
MichaelUrman opened this issue May 26, 2022 · 0 comments
Open

Embedded interfaces are hard to ignore #29

MichaelUrman opened this issue May 26, 2022 · 0 comments

Comments

@MichaelUrman
Copy link
Contributor

When an interface is embedded, the reported interface name isn't what you need to ignore. Concretely, extend wrapcheck/testdata/config_ignoreInterfaceRegexps/main.go with the following, and run the test.

type embedder interface {
	errorer
}

func embed(fn embedder) error {
	var str string
	return fn.Decode(&str) // errorer interface ignored as per `ignoreInterfaceRegexps`
}

Unexpectedly, you'll see the following:

--- FAIL: TestAnalyzer (5.40s)
--- FAIL: TestAnalyzer/config_ignoreInterfaceRegexps (0.25s)
analysistest.go:452: /home/murman/src/wrapcheck/wrapcheck/testdata/config_ignoreInterfaceRegexps/main.go:33:9: unexpected diagnostic: error returned from interface method should be wrapped: sig: func (_/home/murman/src/wrapcheck/wrapcheck/testdata/config_ignoreInterfaceRegexps.errorer).Decode(v interface{}) error

Note that the ignores include errorer and the reported interface is config_ignoreInterfaceRegexps.errorer. However to suppress this you actually need to suppress embedder.

I believe this comes down to the difference between name and fnSig in reportUnwrapped, which come from sel.Sel and sel.X respectively, but the path forward is unclear to me.

name := types.TypeString(pass.TypesInfo.TypeOf(sel.X), func(p *types.Package) string { return p.Name() })
if containsMatch(regexpsInter, name) {
} else {
pass.Reportf(tokenPos, "error returned from interface method should be wrapped: sig: %s", fnSig)

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

No branches or pull requests

1 participant