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

False positive about unused return values #37

Closed
cloudlena opened this issue Jan 24, 2019 · 5 comments
Closed

False positive about unused return values #37

cloudlena opened this issue Jan 24, 2019 · 5 comments

Comments

@cloudlena
Copy link

cloudlena commented Jan 24, 2019

The following code

package main

import "github.com/aws/aws-sdk-go-v2/aws"

func main() {
	_ = aws.EndpointResolverFunc(func(string, string) (aws.Endpoint, error) {
		return aws.Endpoint{URL: "url"}, nil
	})
}

returns the following unparam issue:

main.go:6:67: main$1 - result 1 (error) is always nil

However, I cannot remove that error return value because that would change the function signature and it wouldn't match the one expected by the AWS SDK anymore.

@mvdan
Copy link
Owner

mvdan commented Jan 24, 2019

Thanks. Just to confirm - are you using the latest master version, e6a6d1c? I fixed a few false positives this morning.

@cloudlena
Copy link
Author

Yes, I just downloaded it with go get -u mvdan.cc/unparam.

@mvdan
Copy link
Owner

mvdan commented Jan 24, 2019

I can't reproduce it:

$ cat go.mod
module repro

go 1.12

require github.com/aws/aws-sdk-go-v2 v0.7.0
$ cat f.go
package main

import (
        "fmt"

        "github.com/aws/aws-sdk-go-v2/aws"
)

func main() {
        resolver := aws.EndpointResolverFunc(func(string, string) (aws.Endpoint, error) {
                return aws.Endpoint{}, nil
        })
        fmt.Println(resolver)
}
$ unparam .
$

Could you provide the steps to reproduce the problem within a Docker container? That way I'll very likely be able to reproduce it. For example, the following still doesn't show me any unparam warning:

#!/bin/bash

docker run -i golang:1.11.4-stretch <<-SCRIPT

        echo "installing unparam"
        export GO111MODULE=off # to install unparam properly
        go get -u mvdan.cc/unparam

        echo "setting up temp module"
        export GO111MODULE=on
        mkdir temp
        cd temp
        go mod init temp

        cat >f.go <<FILE
        package main

        import (
                "fmt"

                "github.com/aws/aws-sdk-go-v2/aws"
        )

        func main() {
                resolver := aws.EndpointResolverFunc(func(string, string) (aws.Endpoint, error) {
                        return aws.Endpoint{}, nil
                })
                fmt.Println(resolver)
        }
        FILE
        echo "downloading deps"
        go mod tidy

        echo "running unparam"
        unparam .

SCRIPT

@cloudlena
Copy link
Author

cloudlena commented Jan 24, 2019

Sorry, I just noticed that my example was incomplete and, indeed, didn't reproduce the issue. I fixed it above and simplified the example some more and it should work now to reproduce. I had to add URL: "url" for it to reproduce the issue. It works fine without that part.

@mvdan
Copy link
Owner

mvdan commented Jan 24, 2019

Thanks - I can reproduce now. Should be a simple enough fix.

@mvdan mvdan closed this as completed in 847e86f Jan 24, 2019
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

2 participants