Skip to content

doc: fix imprecision in IO.FS.Stream.getLine and IO.FS.Handle.getLine - #14754

Open
ia0 wants to merge 1 commit into
leanprover:masterfrom
ia0:getline
Open

doc: fix imprecision in IO.FS.Stream.getLine and IO.FS.Handle.getLine#14754
ia0 wants to merge 1 commit into
leanprover:masterfrom
ia0:getline

Conversation

@ia0

@ia0 ia0 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

This PR fixes imprecise documentation for IO.FS.Stream.getLine and IO.FS.Handle.getLine. If the stream does not end with a newline (or line break), then getLine will return a String that does not end with a newline. Reciprocally, this situation can only occur when reaching an EOF.

Note that the documentation of read does not necessarily need to be similarly updated. This is because read will always emit an empty array, even after a partially filled array.

This is based on testing only, not necessarily intent of the code. Here are reproduction steps:

def main : IO Unit := do
  repeat do
    let line ← (← IO.getStdin).getLine
    IO.println s!"XXX{line}YYY"

Running with the following input where % indicates EOF (e.g. using Ctrl-D if there was no input since last newline or EOF, or using Ctrl-D twice there was: once to flush the buffer and once to indicate EOF):

hello

foo%%

gives the following output (when YYY does not start a line, it means getLine did not end with a newline):

XXXhello
YYY
XXX
YYY
XXXfooYYY
XXXYYY

This PR fixes imprecise documentation for `IO.FS.Stream.getLine` and `IO.FS.Handle.getLine`. If the stream does not end with a newline (or line break), then `getLine` will return a `String` that does not end with a newline. Reciprocally, this situation can only occur when reaching an EOF.

Note that the documentation of `read` does not necessarily need to be similarly updated. This is because `read` will always emit an empty array, even after a partially filled array.

This is based on testing only, not necessarily intent of the code. Here are reproduction steps:

```lean4
def main : IO Unit := do
  repeat do
    let line ← (← IO.getStdin).getLine
    IO.println s!"XXX{line}YYY"
```

Running with the following input where `%` indicates EOF (e.g. using Ctrl-D if there was no input since last newline or EOF, or using Ctrl-D twice there was: once to flush the buffer and once to indicate EOF):

```
hello

foo%%
```

gives the following output (when `YYY` does not start a line, it means `getLine` did not end with a newline):

```
XXXhello
YYY
XXX
YYY
XXXfooYYY
XXXYYY
```
@github-actions github-actions Bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Aug 11, 2026
@mathlib-lean-pr-testing

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 8e0b5589d6ad6e4181bc4a98b7dfb17c6c305ba2 --onto 3fc29d37a70f8fd904ebab848557c12383543008. You can force Mathlib CI using the force-mathlib-ci label. (2026-08-11 13:44:45)

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 8e0b5589d6ad6e4181bc4a98b7dfb17c6c305ba2 --onto 3fc29d37a70f8fd904ebab848557c12383543008. You can force reference manual CI using the force-manual-ci label. (2026-08-11 13:44:47)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants