-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
swiftlang/swift-experimental-string-processing
#825Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels
Description
Description
Later transforms from Captures seem to be clobbering the transformed output from earlier Captures in some cases.
Reproduction
A toy mixed-number regex:
import RegexBuilder
let mixedNumberRegex = Regex {
// whole number
Optionally {
Capture {
OneOrMore(.digit)
} transform: { Int($0)! }
OneOrMore { " " }
}
// numerator
Capture {
OneOrMore(.digit)
} transform: { Int($0)! }
"/"
// denominator
Capture {
OneOrMore(.digit)
} transform: { Int($0)! }
}
if let match = try? mixedNumberRegex.wholeMatch(in: "1 3/4") {
print(match.1, match.2, match.3)
}This prints Optional(1) 4 4.
Some further observations:
- If the
Int($0)!transforms are replaced byString($0), you correctly getOptional("1") 3 4. - If you remove the transforms entirely, the Substring matches are correct.
- If you test with input string
"3/4", you correctly getnil 3 4-- no clobbering.
Expected behavior
It prints Optional(1) 3 4.
Environment
swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5)
Target: arm64-apple-macosx15.0
Additional information
No response
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.triage neededThis issue needs more specific labelsThis issue needs more specific labels