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

proposal: strconv: Make FormatInt accept any integer type #58407

Closed
misha-ridge opened this issue Feb 8, 2023 · 2 comments
Closed

proposal: strconv: Make FormatInt accept any integer type #58407

misha-ridge opened this issue Feb 8, 2023 · 2 comments

Comments

@misha-ridge
Copy link

Description

  • Change strconv.FormatInt to be a generic that accepts any integer type.
  • Deprecate strconv.FormatUint and suggest to use strconv.FormatInt instead.

Motivation

During a review of a medium-sized codebase I have noticed that there are two causes of typecasts to the arguments of strconv.Format[U]Int: casting integers to a wider type, and casting non-integers (floats, types based on integers). These two cases are hard to distinguish and as a result of the review we had to add a comment to every typecast.

First type of casts (wider-type casts) ought not exist, they are an artifact of Format[U]Int been created before generics. This proposal gets rid of the useless typecasts of first type, leaving only second, meaningful, typecasts in place.

As far as I can tell this proposal does not break backward compatibility, as it makes FormatInt accept strictly more types than before.

@gopherbot gopherbot added this to the Proposal milestone Feb 8, 2023
@zephyrtronium
Copy link
Contributor

This kind of change is not backward compatible, unfortunately. Code today can write var f = strconv.FormatInt, which would become illegal if FormatInt were given type parameters. See #48287.

@ianlancetaylor
Copy link
Contributor

Unfortunately we can't do this, so closing.

@ianlancetaylor ianlancetaylor closed this as not planned Won't fix, can't repro, duplicate, stale Feb 8, 2023
@golang golang locked and limited conversation to collaborators Feb 8, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants