Skip to content

[5.7] Handle AnyRegexOutput when casting to new Regex #475

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 1 commit into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Sources/_StringProcessing/Utility/TypeVerification.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
@available(SwiftStdlib 5.7, *)
extension Regex {
internal func _verifyType() -> Bool {
guard Output.self != AnyRegexOutput.self else {
return true
}

var tupleElements: [Any.Type] = [Substring.self]
var labels = " "

Expand Down
7 changes: 3 additions & 4 deletions Tests/RegexBuilderTests/AnyRegexOutputTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ extension RegexDSLTests {
) {
let aro = Regex<AnyRegexOutput>(re)

// FIXME: The below fatal errors
let casted = aro//try! XCTUnwrap(Regex(aro, as: Output.self))
let casted = try! XCTUnwrap(Regex(aro, as: Output.self))

// contains(captureNamed:)
checkContains(re, kind)
Expand Down Expand Up @@ -173,15 +172,15 @@ extension RegexDSLTests {
(?x)
(\p{hexdigit}{4}) -? (?<salient>\p{hexdigit}{4}) -?
(\p{hexdigit}{4}) -? (\p{hexdigit}{4})
"""#, as: (Substring, Substring, Substring, Substring, Substring).self),
"""#, as: (Substring, Substring, salient: Substring, Substring, Substring).self),
.salient,
salientOutput
)
check(try! Regex(#"""
(?x)
(\p{hexdigit}{4}) -? (?<note>\p{hexdigit}{4}) -?
(\p{hexdigit}{4}) -? (\p{hexdigit}{4})
"""#, as: (Substring, Substring, Substring, Substring, Substring).self),
"""#, as: (Substring, Substring, note: Substring, Substring, Substring).self),
.note,
noteOutput
)
Expand Down