-
Notifications
You must be signed in to change notification settings - Fork 18k
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
fmt: 7c7cecc should be rolled back #27634
Comments
The Go 1 compability does not guarantee that all programs will work the same way with all versions of Go 1, the compatibility promise gives Go the right to fix bugs. In the issue #26363 it was decided to fix this bug, even if it would change the behavior of existing programs. |
\cc @robpike for decision. I won't be surprised if we keep the new behavior. |
This was already discussed in #27598, and in the original issue where this particular behavior was changed. In general, it's okay if tests that lock in internal behavior break between Go releases. For example, if you depend on exactly what You could say that |
If it were a bug, I'd be very happy for the bug to be fixed, but this looks to me merely like a choice of aesthetic changing. I'd argue strongly that |
It was decided it was a bug, as the value "1" as a Go number is not automatically a floating-point constant and code could care. You can argue about the severity of the bug, and whether it deserves addressing, but it has been addressed, discussed, acted upon, and resolved. I believe the old behavior was incorrect and the new behavior is correct. Yes, it can break some programs. Almost any change can. But this one affects very few. I would prefer we leave things as they are now. If we roll it back, we will have just one release with different behavior and that's even stranger. There have been a number of relatively minor bug fixes like this made over time. They are considered carefully. I assure you that they are never an "aesthetic decision". |
This change was not released. I have found an elegant way to work around the change, but for the record, I think the decision here is wrong. |
And the analogous program using a non-default integer type, which also doesn't print any distinguishing type information: Even if the behavior is not what was originally intended, this change breaks existing tests (including a fair number within Google's internal codebase) for what seems like a marginal benefit. I think we should roll this back. At the very least, a breaking change to (CC @FiloSottile @andybons @rsc) |
It's true that we do need to be able to make fixes, but this one doesn't seem important enough to force the issue. Rob is OK with rolling it back. Please do so. |
Interestingly, I ran into a bug in writing some tests just the other day that arose exactly because the old behaviour exists (assigning a code-generated literal |
If you really need to get the right type out of the print, you should be using %T(%#v) not just %#v. |
Change https://golang.org/cl/142597 mentions this issue: |
What version of Go are you using (
go version
)?Any child of 7c7cecc.
Does this issue reproduce with the latest release?
No.
What operating system and processor architecture are you using (
go env
)?amd64/linux
What did you do?
Run tests for Gonum's mat package.
What did you expect to see?
Pass.
What did you see instead?
Failure because
%#v
now formats floats with a trailing ".0" if the value is integral.For example here.
Test failure
Additional information
I believe this breaks the Go1 compatibility promise, and that it does not do so to fix a bug.
According to the fmt documentation, the
%#v
verb/flag specifies that "a Go-syntax representation of the value" being printed will be output. However, a string without a trailing ".0" is valid Go syntax for float values and so there was no bug.It's true that it is not possible to infer the kind from the representation of the value when the suffix is omitted, but the fmt documentation does not say that this should possible. And already, already type information is lost (for example, even within the builtin types, signed integers are indistinguishable, unsigned integers are indistinguishable, and float types are indistinguishable).
The text was updated successfully, but these errors were encountered: