-
Notifications
You must be signed in to change notification settings - Fork 46
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
Match.subscript fails to properly cast non-matched Capture #624
Comments
There a few things to notice here:
With that said, I don't think there is a bug here(perhaps a better runtime error message), but I'm don't know much about regex feature so I'll let @hamishknight, @natecook1000, @Azoy take a look. |
Nevermind... it works... I had tried:
and it didn't work. Notice the typo... Sorry for the false bug. Grrrr... |
@LucianoPAlmeida but it won't compile for Substring. For example this fails to compile: import RegexBuilder
let ref = Reference(Substring?.self)
let regex = Regex {
"test"
Optionally {
Capture(as: ref) {
OneOrMore(.digit)
}
}
"a"
}
let match = "testa".wholeMatch(of: regex)
print("Substring \(match![ref])") with an error of:
and if I change the ref to:
I get a runtime casting error:
|
Have to look in more depth into it but initially applying a transform hack makes it compile. import RegexBuilder
let ref = Reference(Substring?.self)
let regex = Regex {
"test"
Optionally {
Capture(as: ref) {
OneOrMore(.digit)
} transform: { $0 }
}
"a"
}
let match = "testa".wholeMatch(of: regex)
print("Substring \(match![ref])") Looks like a type checker problem on matching |
This still fails on Xcode Version 15.0 beta (15A5160n). |
This still fails with Xcode 15 final. |
This code should produce an
Optional<Int>
. Instead it produces anOptional<Substring>
and crashes.This aborts with:
Could not cast value of type 'Swift.Optional<Swift.Substring>' (0x1f2db92c0) to 'Swift.Int' (0x1f3da0bf0).
The text was updated successfully, but these errors were encountered: