-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
bytes: Trim returns empty slice instead of nil in 1.18 #51793
Comments
I don't think the API makes any promises about empty vs nil slices. |
To be fair, returning an empty string sound more logical to me then returning null. This change in logic however broke a code base I work on in at least 2 places. But if it doesn’t count as a regression that’s totally fine too, of course. |
This is not guaranteed by the documented behavior, but I'm inclined to say that this is a regression. |
Oh, it's a change in the opposite direction where the new behavior is that it returns non-nil for a non-nil input. I actually think this behavior is more correct. |
I agree the new behavior is more correct, though #31038 was a similar issue in the past |
I think we should revert to the old behavior. The improvement in behavior is pretty minor and doesn't seem worth breaking existing programs. |
I don't see anything wrong with the new behavior, but I agree with @randall77 that on balance we should keep the behavior the same. There's not enough benefit to changing. |
@gopherbot Please open backport issue for 1.18 Assuming we do go ahead and restore the old behavior, as I think we should, we need to backport the fix to 1.18 so that we are consistent across releases. |
Backport issue(s) opened: #51796 (for 1.18). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases. |
Change https://go.dev/cl/393876 mentions this issue: |
I also think the new behavior was more intuitive and internally consistent, but I'm ok with that partial revert if it's hurting users. Would just be nice if we had a way to get rid of these paper cuts over time (IIRC at a certain point there was a discussion about using the go version in go.mod for this?), or maybe we could start aggressively randomizing non-guaranteed behavior during testing. (Obviously, this specific instance of the problem is not important enough by itself, but having a structured, documented approach would certainly help in the long run) |
Change https://go.dev/cl/396294 mentions this issue: |
… nil Keep returning nil for the cases where we historically returned nil, even though this is slightly different for TrimLeft and TrimRight. For #51793 Fixes #51796 Change-Id: Ifbdfc6b09d52b8e063cfe6341019f9b2eb8b70e9 Reviewed-on: https://go-review.googlesource.com/c/go/+/393876 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> (cherry picked from commit 32fdad1) Reviewed-on: https://go-review.googlesource.com/c/go/+/396294 Reviewed-by: Austin Clements <austin@google.com>
What version of Go are you using (
go version
)?go version go1.18 darwin/arm64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
Test should succeed (it succeeds on Go 1.17)
What did you see instead?
Test fails
The text was updated successfully, but these errors were encountered: