Skip to content

Commit 6143e7e

Browse files
committed
Fix 5.10 compile issue
1 parent 2022514 commit 6143e7e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Sources/SemanticVersion/SemanticVersion.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ extension SemanticVersion.PreReleaseIdentifier: Comparable {
116116
}
117117

118118

119+
#if compiler(>=6)
119120
extension 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)
135153
extension SemanticVersion: Sendable {}

0 commit comments

Comments
 (0)