io: documentation for ByteScanner and RuneScanner does not match common implementations #48449
Labels
Documentation
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
What version of Go are you using (
go version
)?go1.17.1
Does this issue reproduce with the latest release?
Yes.
What did you do?
Compare the documentation for
io.ByteScanner
andio.RuneScanner
to the behavior of common standard-library implementations (strings.Reader
,bytes.Reader
,bytes.Buffer
,bufio.Reader
).What did you expect to see?
Behavior consistent with the
io
interface documentation (https://pkg.go.dev/io@go1.17.1#ByteScanner):What did you see instead?
A mix of reasonable and less-reasonable behaviors, none of which match the
io
interface documentation.strings.Reader
andbytes.Reader
.UnreadByte
functions likeSeek(-1, io.SeekCurrent)
. It returnsnil
as long as the current offset is ≥ 1, even if no read at all has occurred (such as if the offset has only been moved bySeek
).UnreadRune
returnsnil
only if the last method call that adjusted the offset wasUnreadRune
, even if the portion of the buffer immediately ahead of the current offset contains a complete, valid rune.bytes.Buffer
:UnreadByte
returnsnil
as long as the last operation was any kind ofRead
, orNext
(but notWriteTo
, which is similarlyRead
-like).UnreadRune
returnsnil
only if the last operation wasReadRune
.bufio.Reader
:UnreadByte
returnsnil
as long as the last operation was any kind ofRead
, modulo buggy tracking for a few methods (bufio: Reader.UnreadByte after Discard silently corrupts input #48446).UnreadRune
returnsnil
only if the last operation wasReadRune
(modulo the aforementioned bug).As in #48316, I think that given the long-established behaviors of these implementations we must fix the
io
interface documentation instead of the de-facto behavior. I suggest that we change the documentation to read:CC @robpike @griesemer @bradfitz @ianlancetaylor
The text was updated successfully, but these errors were encountered: