`String.Slice.revSplit` drops the empty piece at the start of the slice
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- backend-api-design
Research direction
Start with RevSplitIterator.step in src/Init/Data/String/Slice/Pattern.lean and compare its finished-searcher case with SplitIterator. Reproduce the issue with the minimal Lean program in the report, including the empty-slice and leading-separator cases. Done when revSplit returns the same pieces as split in reverse order, with the existing test suite covering the behavior.
Written by the indexing model from the issue text.
Description
Prerequisites
- Check that your issue is not already filed: searched for
revSplit,Slice.split,String.Slice splitandsplit empty slice. - Reduce the issue to a minimal, self-contained, reproducible test case. Avoid dependencies to Mathlib or Batteries.
- Test your test case against the latest nightly release.
Description
String.Slice.revSplit leaves out the leftmost piece when it is empty. A slice that starts with a separator, or an empty slice, gives one piece fewer than String.Slice.split. A separator at the end does give an empty piece, so the two ends behave differently:
def main : IO Unit := do
IO.println (repr <| (",x".toSlice.split ',').toList.map (·.copy))
IO.println (repr <| (",x".toSlice.revSplit ',').toList.map (·.copy))
IO.println (repr <| ("x,".toSlice.revSplit ',').toList.map (·.copy))
IO.println (repr <| ("".toSlice.revSplit ',').toList.map (·.copy))
lean --run RevSplit.lean
# expected: # actual:
["", "x"] ["", "x"]
["x", ""] ["x"]
["", "x"] ["", "x"]
[""] []
Likewise "aa".toSlice.split 'a' gives three empty pieces and "aa".toSlice.revSplit 'a' gives two. The Char → Bool pattern form behaves the same way.
The revSplit docstring matches the split docstring apart from the direction ("starting from the end of the slice and traversing towards the start ... If multiple subslices in a row match the pattern, the resulting list will contain empty slices"), so revSplit should give the pieces of split in reverse order.
In RevSplitIterator.step (src/Init/Data/String/Slice/Pattern.lean), when the searcher is done, the remaining piece s.sliceTo currPos is yielded only if currPos ≠ s.startPos. The forward SplitIterator yields its remaining piece unconditionally.
Expected behavior: revSplit gives the same pieces as split, in reverse order.
Actual behavior: the leftmost empty piece is missing.
Versions
4.37.0-nightly-2026-11-05 ["x"] / []
4.36.0-rc2 ["x"] / []
4.35.0 ["x"] / []
These are on macOS arm64 (official toolchains via elan), and Linux x86_64 gives the same results. Nothing under src/Init/Data/String/ has changed on master since the nightly. The code came in with #10514.
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask
them to add 👍 to it.
Found by an automated differential tester (ephyra); this report was drafted with AI assistance.
- Dominant language
- Lean
- Stars
- 10.3k
- Forks
- 1.1k
- Avg merge
- 19h 8m
- Merged PRs (30d)
- 421
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from leanprover/lean4
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16681 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
leanprover/lean4#16299 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
leanprover/lean4#16257 ·
Maintainers usually reply within 1 day
-
`IO.FS.realPath` reports every failure as `noFileOrDirectory` instead of classifying by `errno`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
leanprover/lean4#15683 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
leanprover/lean4#15626 ·
Maintainers usually reply within 1 day
All issues in leanprover/lean4
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
vllm-project/vllm-sail#398 ·
Maintainers usually reply within 1 day
-
kubernetes-ingestor: fetchCRDMapping() runs even when crossplane.enabled is false, logging a 403 ERROR every runPossibly taken @kc9ddi claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
TeraSky-OSS/backstage-plugins#228 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
nightscout/nocturne#4057 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
opendatalab/MinerU#5800 · 2 comments ·
Maintainers usually reply within 1 day