Open
Description
This code should produce an Optional<Int>
. Instead it produces an Optional<Substring>
and crashes.
import RegexBuilder
let ref = Reference(Int.self)
let regex = Regex {
"test"
Optionally {
TryCapture(as: ref) {
OneOrMore(.digit)
} transform: {
Int($0)
}
}
"a"
}
let match = "testa".wholeMatch(of: regex)
print("Int \(match![ref])")
This aborts with:
Could not cast value of type 'Swift.Optional<Swift.Substring>' (0x1f2db92c0) to 'Swift.Int' (0x1f3da0bf0).