Skip to content

Commit f2e44de

Browse files
authored
[CoreInternal] Add explicit generics typing for Array.Index usage (2) (#10176)
1 parent 3afc2b3 commit f2e44de

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

FirebaseCore/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Firebase 9.6.0
2+
- [fixed] Fixed `Array.Index`-related compile time errors when building with older Swift versions. (#10171)
23
- [fixed] Update dependency specification for GTMSessionFetcher to allow all 2.x versions. (#10131)
34

45
# Firebase 9.5.0

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatController.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@ public final class HeartbeatController {
103103
)
104104
}
105105

106-
// Synchronously gets and returns the stored heartbeats, resetting storage
107-
// using the given transform. If the operation throws, assume no
108-
// heartbeat(s) were retrieved or set.
109-
if let heartbeatsBundle = try? storage.getAndSet(using: resetTransform) {
110-
return heartbeatsBundle.makeHeartbeatsPayload()
111-
} else {
106+
do {
107+
// Synchronously gets and returns the stored heartbeats, resetting storage
108+
// using the given transform.
109+
let heartbeatsBundle = try storage.getAndSet(using: resetTransform)
110+
// If no heartbeats bundle was stored, return an empty payload.
111+
return heartbeatsBundle?.makeHeartbeatsPayload() ?? HeartbeatsPayload.emptyPayload
112+
} catch {
113+
// If the operation throws, assume no heartbeat(s) were retrieved or set.
112114
return HeartbeatsPayload.emptyPayload
113115
}
114116
}

FirebaseCore/Internal/Sources/HeartbeatLogging/HeartbeatsBundle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ struct HeartbeatsBundle: Codable, HeartbeatsPayloadConvertible {
7272
lastAddedHeartbeatDates[$0] = heartbeat.date
7373
}
7474

75-
} catch let error as RingBufferError {
75+
} catch let error as RingBuffer<Heartbeat>.Error {
7676
// A ring buffer error occurred while pushing to the buffer so the bundle
7777
// is reset.
7878
self = HeartbeatsBundle(capacity: capacity)

FirebaseCore/Internal/Sources/HeartbeatLogging/RingBuffer.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@
1414

1515
import Foundation
1616

17-
/// Error types for `RingBuffer` operations.
18-
enum RingBufferError: LocalizedError {
19-
case outOfBoundsPush(pushIndex: Array.Index, endIndex: Array.Index)
20-
21-
var errorDescription: String {
22-
switch self {
23-
case let .outOfBoundsPush(pushIndex, endIndex):
24-
return "Out-of-bounds push at index \(pushIndex) to ring buffer with" +
25-
"end index of \(endIndex)."
26-
}
27-
}
28-
}
29-
3017
/// A generic circular queue structure.
3118
struct RingBuffer<Element>: Sequence {
3219
/// An array of heartbeats treated as a circular queue and intialized with a fixed capacity.
3320
private var circularQueue: [Element?]
3421
/// The current "tail" and insert point for the `circularQueue`.
3522
private var tailIndex: Array<Element?>.Index
3623

24+
/// Error types for `RingBuffer` operations.
25+
enum Error: LocalizedError {
26+
case outOfBoundsPush(pushIndex: Array<Element?>.Index, endIndex: Array<Element?>.Index)
27+
28+
var errorDescription: String {
29+
switch self {
30+
case let .outOfBoundsPush(pushIndex, endIndex):
31+
return "Out-of-bounds push at index \(pushIndex) to ring buffer with" +
32+
"end index of \(endIndex)."
33+
}
34+
}
35+
}
36+
3737
/// Designated initializer.
3838
/// - Parameter capacity: An `Int` representing the capacity.
3939
init(capacity: Int) {
@@ -54,7 +54,7 @@ struct RingBuffer<Element>: Sequence {
5454

5555
guard circularQueue.indices.contains(tailIndex) else {
5656
// We have somehow entered an invalid state (#10025).
57-
throw RingBufferError.outOfBoundsPush(
57+
throw Self.Error.outOfBoundsPush(
5858
pushIndex: tailIndex,
5959
endIndex: circularQueue.endIndex
6060
)

0 commit comments

Comments
 (0)