Skip to content

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

@ianlancetaylor

Description

@ianlancetaylor
Contributor

#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.

Activity

added
NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
on Jun 7, 2019
added this to the Go1.14 milestone on Jun 7, 2019
agnivade

agnivade commented on Jun 8, 2019

@agnivade
Contributor
networkimprov

networkimprov commented on Jun 8, 2019

@networkimprov

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

mvdan

mvdan commented on Jun 24, 2019

@mvdan
Member

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

alanfo

alanfo commented on Jun 27, 2019

@alanfo

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

dolmen commented on Jul 2, 2019

@dolmen
Contributor

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

networkimprov

networkimprov commented on Jul 2, 2019

@networkimprov

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

alanfo

alanfo commented on Jul 2, 2019

@alanfo

@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 :(

modified the milestones: Go1.14, Backlog on Oct 9, 2019
modified the milestones: Backlog, Go1.15 on Nov 5, 2019
added
NeedsFixThe path to resolution is known, but the work has not been done.
on Nov 5, 2019

244 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.Proposal-Acceptedokay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1release-blocker

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @bradfitz@toothrot@josharian@rsc@dolmen

        Issue actions

          cmd/vet: warn about string(int) type conversions · Issue #32479 · golang/go