-
Notifications
You must be signed in to change notification settings - Fork 50
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
When a RegexBuilder pattern includes an optional, transformed capture, and the capture is nil, converting the match to AnyRegexOutput and then accessing the capture's type shows Substring? instead of the transformed type.
let pattern = Regex {
Capture(OneOrMore(.digit)) { Int($0)! }
Optionally {
"."
Capture(OneOrMore(.digit)) { Int($0)! }
}
}
for str in ["123.456", "789"] {
if let match = str.wholeMatch(of: pattern) {
print(match.output)
let erasedMatch = Regex<AnyRegexOutput>.Match(match)
print(erasedMatch[1].type, erasedMatch[2].type)
}
}
// Output:
// ("123.456", 123, Optional(456))
// Int Optional<Int>
// ("789", 789, nil)
// Int Optional<Substring>Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working