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

bytes: Reader.Size method documentation is inaccurate #54018

Closed
kbolino opened this issue Jul 23, 2022 · 2 comments
Closed

bytes: Reader.Size method documentation is inaccurate #54018

kbolino opened this issue Jul 23, 2022 · 2 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@kbolino
Copy link

kbolino commented Jul 23, 2022

What version of Go are you using (go version)?

Documentation issue; currently visible default version is 1.18.4

Does this issue reproduce with the latest release?

Yes, 1.18.4 is the latest release. This doesn't seem to have been fixed as of 1.19rc2 either.

What operating system and processor architecture are you using (go env)?

N/A (platform-agnostic documentation issue)

What did you do?

Viewed the docs for Reader.Size method in bytes standard library package

What did you expect to see?

The Reader.Reset method can change the underlying byte slice. The docs for Size method should say something like (changes italicized):

Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value will not change between calls unless the byte slice is changed by Reset.

What did you see instead?

The docs currently say:

Size returns the original length of the underlying byte slice. Size is the number of bytes available for reading via ReadAt. The returned value is always the same and is not affected by calls to any other method.

The Reset method is the only violation of this wording, and it was added in Go 1.7, but the Size method dates back to 1.5. This minor documentation issue seems to have arisen because an assumption (immutability of the byte slice) changed between versions of the language/library.

@dsnet
Copy link
Member

dsnet commented Jul 23, 2022

Your analysis looks right, we should update the documentation.

kucukaslan added a commit to kucukaslan/go that referenced this issue Jul 23, 2022
The Reset method changes the underlying byte array, so it actually changes the return value of the Size method.

Fixes golang#54018
@gopherbot
Copy link

Change https://go.dev/cl/419237 mentions this issue: bytes: document that Reset method changes the return value of Size method

@mvdan mvdan removed the help wanted label Jul 24, 2022
@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label Jul 25, 2022
@cherrymui cherrymui added this to the Backlog milestone Jul 25, 2022
@dmitshur dmitshur modified the milestones: Backlog, Go1.19 Aug 1, 2022
jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
The Reader.Reset changes the underlying byte slice, so it actually
changes the return value of the Size method.

Fixes golang#54018

Change-Id: I160deaa2244e95cb93303cb5dfb67a8d90a375ef
GitHub-Last-Rev: b04724a
GitHub-Pull-Request: golang#54020
Reviewed-on: https://go-review.googlesource.com/c/go/+/419237
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
@golang golang locked and limited conversation to collaborators Aug 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants