Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Sources/SWBProtocol/Message.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,14 @@ public struct IPCMessage: Serializable, Sendable {
/// Reverse name mapping.
static let messageNameToID: [String: any Message.Type] = {
var result = [String: any Message.Type]()
#if DEBUG
var seenMessageNames: Set<String> = []
for messageType in messageTypes {
if !seenMessageNames.insert(messageType.name).inserted {
assertionFailure("Multiple message types registered for same name: \(messageType.name)")
}
}
#endif
for type in IPCMessage.messageTypes {
result[type.name] = type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ahoppen nit: I would have suggested just doing it here, unconditionally (not behind DEBUG), rather than having a second loop:

if let oldValue = result.updateValue(type, forKey: type.name) {
    fatalError("Multiple message types registered for same name: \(type.name)")
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we go: #764

}
Expand Down