Skip to content

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

Closed

Description

@ianlancetaylor

#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

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

    @agnivade
    Contributor
  4. networkimprov commented on Jun 8, 2019

    @networkimprov

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

  5. mvdan commented on Jun 24, 2019

    @mvdan
    Member

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

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

  7. dolmen commented on Jul 2, 2019

    @dolmen
    Contributor

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

  8. networkimprov commented on Jul 2, 2019

    @networkimprov

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

  9. 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 :(

  10. modified the milestones: Go1.14, Backlog on Oct 9, 2019
  11. modified the milestones: Backlog, Go1.15 on Nov 5, 2019
  12. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Nov 5, 2019
  13. removed
    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.
    on Nov 5, 2019
  14. 144 remaining items

  15. added a commit that references this issue on Sep 15, 2021
  16. added a commit that references this issue on Sep 27, 2021
  17. locked and limited conversation to collaborators on Oct 21, 2021
  18. moved this to Accepted in Proposalson Aug 10, 2022
  19. removed this from Proposalson Oct 19, 2022
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

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions