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

Flag unnecessary type conversions #936

Open
Jacalz opened this issue Feb 21, 2021 · 3 comments
Open

Flag unnecessary type conversions #936

Jacalz opened this issue Feb 21, 2021 · 3 comments

Comments

@Jacalz
Copy link

Jacalz commented Feb 21, 2021

At the moment, staticcheck does not seem to be flagging any unnecessary type conversions. I have seen one or two lately. I don't know if it is a bug or that there simply isn't a check for it, but I assume the latter.

Incorrect code:

func print(a int64) {
    fmt.Println(a)
}

func main() {
   a := int64(2)
   print(int64(a))
}

Correct code:

func print(a int64) {
    fmt.Println(a)
}

func main() {
   a := int64(2)
   print(a)
}

Probably related to #128

@Jacalz Jacalz added the needs-triage Newly filed issue that needs triage label Feb 21, 2021
@dominikh
Copy link
Owner

Non-trivial because of build tags, see https://github.com/mdempsky/unconvert

@dominikh dominikh added new-check and removed needs-triage Newly filed issue that needs triage labels Feb 21, 2021
@Jacalz
Copy link
Author

Jacalz commented Feb 23, 2021

Ah, I see. This was just something that I had expected staticcheck to do.

@dominikh
Copy link
Owner

I'm currently working on better support for build tags, after which I may look at this again.

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

No branches or pull requests

2 participants