-
Notifications
You must be signed in to change notification settings - Fork 26
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
Consider reporting avoidable type conversion for untyped constants (typed constants are already handled). #20
Comments
Not sure if this is the same issue, or another but related one...
package main
import (
"fmt"
)
func main() {
var s []string
fmt.Println(s)
s = []string(nil)
fmt.Println(s)
} The conversion of Using |
Interesting. So strictly speaking, That said, I think there's merit to supporting these cases. Maybe behind a flag. The second one can probably already be handled by recognizing that The first case is theoretically just an issue of recognizing another safe context, but it's a bit trickier because of the extra string concatenation. |
Very good point about the distinction between typed vs untyped constants. I agree that supporting it would still be helpful, but being able to control this behavior via a flag would also make sense. |
I've confirmed, if I change the const in the original program from untyped string to typed string, by doing this: -const foo = "foo"
+const foo string = "foo" Or this: -const foo = "foo"
+const foo = string("foo") Then
I'll rename this issue to more accurately represent this issue, which is now more of a feature request. It's not that
It seems to handle that part fine. I'm not too surprised, given you're using |
Consider the following Go program:
I expected
unconvert
to report thatstring(foo)
is an unnecessary conversion, but it didn't.Is that intentional, or a missing feature?
Tested using Go 1.8beta2 and latest version of
unconvert
and its depenencies:/cc @dominikh in case this is a better fit for one of your tools.
The text was updated successfully, but these errors were encountered: