Skip to content

Embedded interfaces are hard to ignore #29

Description

@MichaelUrman

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions