Skip to content

Commit e0a2670

Browse files
authored
Improve an explanatory comment in Dictionary (#20540)
It took me a little while to figure out why we were fatalError()ing in such a convoluted way in Dictionary.init(uniqueKeysWithValues:); the next person to look at this code won’t waste that time.
1 parent b02e48f commit e0a2670

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,10 @@ public struct Dictionary<Key: Hashable, Value> {
481481
var native = _NativeDictionary<Key, Value>(
482482
capacity: keysAndValues.underestimatedCount)
483483
// '_MergeError.keyCollision' is caught and handled with an appropriate
484-
// error message one level down, inside native.merge(_:...).
484+
// error message one level down, inside native.merge(_:...). We throw an
485+
// error instead of calling fatalError() directly because we want the
486+
// message to include the duplicate key, and the closure only has access to
487+
// the conflicting values.
485488
try! native.merge(
486489
keysAndValues,
487490
isUnique: true,

0 commit comments

Comments
 (0)