Repository navigation
Conversation
Groups quantified {0} or {0,0} never run, so nested captures must
stay nil. Skipping the body was still emitting begin/end capture,
which stored an empty match at the current position.
Fixes swiftlang#902.
hippi345
marked this pull request as ready for review
October 17, 2026 09:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Matching
(a){0}b(and(a){0,0}b) against"b"reported the capture as an empty match ("") instead ofnil. A group quantified{0}never participates, so its capture must stay unset, consistent with(a)?b,(a)*b, and(a){0,1}b.The
{0}/{0,0}compiler path dropped the quantified body but still emitted begin/end capture around the skip, which stored an empty range at the current position. This change still drops the never-run body and still allocates capture registers (so later groups keep the correct numbering), but it no longer begins or ends those captures.Fixes #902
Changes
emitQuantification, skip a{0}/{0,0}operand withpreservingCaptures: falseandallocatingCaptures: true.skipNodeallocates nested capture registers when requested, without recording an empty match.flatCaptureTestcoverage for(a){0}b,(a){0,0}b, nested((a)){0}(b), and a{0,1}regression check.Testing
Fail-before (unmodified compiler,
swift test --filter testMatchCaptureBehavior):Pass-after (
swift test --filter testMatchCaptureBehavior, then RegexTests target):This change was prepared with AI assistance and reviewed by the author.