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

cmd/vet: warn about string(int) type conversions #32479

Open
ianlancetaylor opened this issue Jun 7, 2019 · 7 comments

Comments

@ianlancetaylor
Copy link
Contributor

commented Jun 7, 2019

#3939 proposes removing the explicit type conversion string(i) where i has an integer type other than rune. That is a backward incompatible change, so we cannot make it until we can count on having modules everywhere, with the support modules provide for determining the version of the language to use to compile code.

There is a step we can take today, which is to change go vet to report conversions of integer types other than rune to string. If we think that removing this feature from the language is a good idea, then a vet check for it is a good idea, and it is one that we can implement today.

@ianlancetaylor ianlancetaylor added this to the Go1.14 milestone Jun 7, 2019
@agnivade

This comment has been minimized.

Copy link
Member

commented Jun 8, 2019

@networkimprov

This comment has been minimized.

Copy link

commented Jun 8, 2019

Pls also permit string(b) where b is a byte or uint8.

@mvdan

This comment has been minimized.

Copy link
Member

commented Jun 24, 2019

This seems fine to me. The warning should probably point the user in the right direction.

@alanfo

This comment has been minimized.

Copy link

commented Jun 27, 2019

Pls also permit string(b) where b is a byte or uint8.

I think this is essential if this proposal (and eventually #3939) is to be adopted.

The string(byte) conversion, when you're dealing with ASCII characters only, is probably used at least as often as string(rune)in my experience.

@dolmen

This comment has been minimized.

Copy link

commented Jul 2, 2019

@networkimprov @alanfo You will still be able to use string([]byte{b}).

@networkimprov

This comment has been minimized.

Copy link

commented Jul 2, 2019

That would be a surprising requirement. And allocates a byte slice for a single statement?

@alanfo

This comment has been minimized.

Copy link

commented Jul 2, 2019

@dolmen

You will still be able to use string([]byte{b}).

Well string(rune(b)) would be a better alternative because you wouldn't then have to allocate a byte slice but it would still be a nuisance to have to update all my code to use this workaround :(

@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.