Skip to content

Commit 5f32944

Browse files
authored
Merge pull request #15569 from lorentey/detect-mutations
[stdlib] Set, Dictionary: Clarify assert message when a duplicate key is found
2 parents 27c88a9 + 96d93a4 commit 5f32944

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

stdlib/public/core/Dictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2557,8 +2557,8 @@ extension _NativeDictionaryBuffer where Key: Hashable
25572557
@_versioned // FIXME(sil-serialize-all)
25582558
internal func unsafeAddNew(key newKey: Key, value: Value) {
25592559
let (i, found) = _find(newKey, startBucket: _bucket(newKey))
2560-
_sanityCheck(
2561-
!found, "unsafeAddNew was called, but the key is already present")
2560+
_precondition(
2561+
!found, "Duplicate key found in Dictionary. Keys may have been mutated after insertion")
25622562
initializeKey(newKey, value: value, at: i.offset)
25632563
}
25642564

stdlib/public/core/Set.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2161,8 +2161,8 @@ extension _NativeSetBuffer where Element: Hashable
21612161
@_versioned // FIXME(sil-serialize-all)
21622162
internal func unsafeAddNew(key newKey: Element) {
21632163
let (i, found) = _find(newKey, startBucket: _bucket(newKey))
2164-
_sanityCheck(
2165-
!found, "unsafeAddNew was called, but the key is already present")
2164+
_precondition(
2165+
!found, "Duplicate element found in Set. Elements may have been mutated after insertion")
21662166
initializeKey(newKey, at: i.offset)
21672167
}
21682168

0 commit comments

Comments
 (0)