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

don't warn when removing all result parameters would add complexity to the code #24

Open
mvdan opened this issue Mar 1, 2018 · 1 comment

Comments

@mvdan
Copy link
Owner

mvdan commented Mar 1, 2018

For example, say that the result of foo here is never used, as it's always called like foo() or _ = foo():

func foo() bar {
    if cond {
        return foo2()
    }
    return foo3()
}

However, following unparam's advice to remove the result parameter will make the code longer:

func foo() {
    if cond {
        foo2()
        return
    }
    foo3()
}

A couple of examples from go version devel +4a52452a2f Wed Feb 28 22:05:23 2018 +0000 linux/amd64:

regexp/syntax/parse.go:297:27: (*parser).concat - result 0 (*regexp/syntax.Regexp) is never used
regexp/syntax/parse.go:317:30: (*parser).alternate - result 0 (*regexp/syntax.Regexp) is never used
@mvdan mvdan self-assigned this Mar 1, 2018
@mvdan
Copy link
Owner Author

mvdan commented Mar 1, 2018

The rule here should probably be "can all return call() lines be rewritten as call() without changing the behavior?". That will only be true if there is a single return, and it is at the end of the main block.

@mvdan mvdan removed their assignment May 5, 2021
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