I thought the problem was with Xcode 12 beta 3, but it shows up when I switched back to Xcode 11.6. This is in a macOS playground on a Catalina system.
public protocol PatternMatcher {
associatedtype Element
func matchingPrefix<C: Collection>(for collection: C) -> C.Index?
where C.Element == Element
}
internal enum MatchCount<Count: BinaryInteger>: Hashable {
case atLeast(Count)
case within(ClosedRange<Count>)
}
public struct PredicatePatternMatcher<Element, Count: BinaryInteger> {
let counts: MatchCount<Count>
let isMatch: (Element) -> Bool
public init(count: PartialRangeFrom<Count>, predicate: @escaping (Element) -> Bool) {
precondition(count.lowerBound >= 0)
counts = .atLeast(count.lowerBound)
isMatch = predicate
}
public init(count: ClosedRange<Count>, predicate: @escaping (Element) -> Bool) {
precondition(count.lowerBound >= 0)
counts = .within(count)
isMatch = predicate
}
}
extension PredicatePatternMatcher: PatternMatcher {
public func matchingPrefix<C: Collection>(for collection: C) -> C.Index?
where C.Element == Element {
// The error is on "minIndex"
let cStart = collection.startIndex, cEnd = collection.endIndex
guard let minIndex = collection.index(cStart, offsetBy: counts.minimumCount, limitedBy: cEnd) else {
return nil
}
return nil // for now
}
}
The error at the guard
is:
'index(_:offsetBy:limitedBy:)' is unavailable: all index distances are now of type Int
I have no idea why my invocation of a core method of Collection
is being confused with the now-obsolete IndexDistance
.