Skip to content

Commit cc83fa6

Browse files
committed
[Dispatch] Don't crash when comparing DispatchWallTimes with <
1 parent 3cd0087 commit cc83fa6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

stdlib/public/SDK/Dispatch/Time.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public struct DispatchWallTime : Comparable {
7474

7575
public func <(a: DispatchWallTime, b: DispatchWallTime) -> Bool {
7676
if a.rawValue == ~0 || b.rawValue == ~0 { return false }
77-
return -Int64(a.rawValue) < -Int64(b.rawValue)
77+
return -Int64(bitPattern: a.rawValue) < -Int64(bitPattern: b.rawValue)
7878
}
7979

8080
public func ==(a: DispatchWallTime, b: DispatchWallTime) -> Bool {

test/stdlib/Dispatch.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,19 @@ DispatchAPI.test("dispatch_data_t deallocator") {
8585
expectEqual(1, t)
8686
}
8787
}
88+
89+
DispatchAPI.test("DispatchTime comparisons") {
90+
do {
91+
let now = DispatchTime.now()
92+
checkComparable([now, now + .milliseconds(1)], oracle: {
93+
return $0 < $1 ? .lt : $0 == $1 ? .eq : .gt
94+
})
95+
}
96+
97+
do {
98+
let now = DispatchWallTime.now()
99+
checkComparable([now, now + .milliseconds(1)], oracle: {
100+
return $0 < $1 ? .lt : $0 == $1 ? .eq : .gt
101+
})
102+
}
103+
}

0 commit comments

Comments
 (0)