Skip to content

[5.7] Flatten optional nesting for regex literal captures #552

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

Merged
merged 6 commits into from
Jul 6, 2022

Conversation

hamishknight
Copy link
Contributor

5.7 cherry-pick of #545

When computing the CaptureList for AST nodes, including converted AST -> DSL nodes, only permit at most one level of optionality. This means that regex literal captures are now either Substring or Substring?.

Optional nesting is however still performed in the DSL (due to result builder limitations). If a regex literal is nested in the DSL, it may only add at most one extra level of optionality to the current nesting level.

Additionally, change the value of a failed nested optional capture from .some(nil) to nil.

Resolves #399
Resolves #543
rdar://96505893

This doesn't appear to be used.
Previously we would wrap a `nil` in
`optionalCount - 1` outer layers of `.some(...)`.
Change this to return an `optionalCount` nested
optional with a top-level value of `nil`.
When computing the CaptureList for AST nodes,
including converted AST -> DSL nodes, only permit
at most one level of optionality. This means that
regex literal captures are now either `Substring`
or `Substring?`.

Optional nesting is however still performed in the
DSL (due to result builder limitations). If a
regex literal is nested in the DSL, it may only
add at most one extra level of optionality to the
current nesting level.
This is no longer needed as the capture list has
the right nesting information.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

Previously we would ignore the case where the
match fails, but the test expects the match to
succeed.
@hamishknight
Copy link
Contributor Author

@swift-ci please test

@hamishknight hamishknight merged commit 65178f9 into swiftlang:swift/release/5.7 Jul 6, 2022
@hamishknight hamishknight deleted the flatpak-5.7 branch July 6, 2022 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
r5.7 5.7 Release Cherry Picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants