File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -116,6 +116,7 @@ extension SemanticVersion.PreReleaseIdentifier: Comparable {
116116}
117117
118118
119+ #if compiler(>=6)
119120extension Array : @retroactive Comparable where Element == SemanticVersion . PreReleaseIdentifier {
120121 public static func < ( lhs: Self , rhs: Self ) -> Bool {
121122 // Per section 11.4 of the semver spec, compare left to right until a
@@ -130,6 +131,23 @@ extension Array: @retroactive Comparable where Element == SemanticVersion.PreRel
130131 return lhs. count < rhs. count
131132 }
132133}
134+ #else
135+ extension Array : @retroactive Comparable where Element == SemanticVersion . PreReleaseIdentifier {
136+ public static func < ( lhs: Self , rhs: Self ) -> Bool {
137+ // Per section 11.4 of the semver spec, compare left to right until a
138+ // difference is found.
139+ // See: https://semver.org/#spec-item-11
140+ for (lhIdentifier, rhIdentifier) in zip ( lhs, rhs) {
141+ if lhIdentifier != rhIdentifier { return lhIdentifier < rhIdentifier }
142+ }
143+
144+ // 11.4.4 - A larger set of identifiers will have a higher precendence
145+ // than a smaller set, if all the preceding identifiers are equal.
146+ return lhs. count < rhs. count
147+ }
148+ }
149+ #endif
150+
133151
134152#if swift(>=5.5)
135153extension SemanticVersion : Sendable { }
You can’t perform that action at this time.
0 commit comments