-
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: (*Buffer).UnreadRune at EOF unexpectedly returns an error #19522
Comments
/cc @robpike |
Seems like it should be fine to unread a rune at EOF, so I would say "bug". But I am not the one who's going to fix it. @griesemer maybe? |
I am inclined to say that current behavior is the documented behavior. Note that the documentation says:
If
For It doesn't seem worthwhile adding complexity for a corner case especially given that the current semantics is quite reasonable. It's also reasonable to expect that a well-written program doesn't call Fixing this by clarifying the documentation and error message, plus extra tests. |
CL https://golang.org/cl/42020 mentions this issue. |
The documentation for
(*bytes.Buffer).UnreadRune
says:From this description alone, one might reasonably expect that after
ReadRune
returnsio.EOF
,UnreadRune
is a no-op and returnsnil
.However,
UnreadRune
at EOF currently returns an error (https://play.golang.org/p/DyRzp8-W8q):bytes.Buffer: UnreadRune: previous operation was not ReadRune
The error message is misleading: the previous operation was, in fact,
ReadRune
— it just happened to returnio.EOF
.It is not obvious to me whether this is a bug in
UnreadRune
, an unclear error message, or unclear documentation.The text was updated successfully, but these errors were encountered: