Skip to content

Commit f7ba02a

Browse files
gribozavrtkremenek
authored andcommitted
[stdlib] Fix _writeBackMutableSlice error messages (#2723)
1 parent 0932222 commit f7ba02a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stdlib/public/core/WriteBackMutableSlice.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ internal func _writeBackMutableSlice<
3939

4040
_precondition(
4141
selfElementIndex == selfElementsEndIndex,
42-
"Cannot replace a slice of a MutableCollection with a slice of a larger size")
42+
"Cannot replace a slice of a MutableCollection with a slice of a smaller size")
4343
_precondition(
4444
newElementIndex == newElementsEndIndex,
45-
"Cannot replace a slice of a MutableCollection with a slice of a smaller size")
45+
"Cannot replace a slice of a MutableCollection with a slice of a larger size")
4646
}
4747

validation-test/stdlib/CollectionType.swift.gyb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,26 @@ CollectionTypeTests.test("subscript(_: Range<Index>)/writeback") {
588588
[ 1, 2, 3, 4, 5, 0, -1, -2, -3, -4 ], collection)
589589
}
590590

591+
CollectionTypeTests.test("subscript(_: Range<Index>)/defaultImplementation/sliceTooLarge")
592+
.crashOutputMatches("Cannot replace a slice of a MutableCollection with a slice of a larger size")
593+
.code {
594+
var x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
595+
expectCrashLater()
596+
x.withUnsafeMutableBufferPointer { buffer in
597+
buffer[2..<4] = buffer[4..<8]
598+
}
599+
}
600+
601+
CollectionTypeTests.test("subscript(_: Range<Index>)/defaultImplementation/sliceTooSmall")
602+
.crashOutputMatches("Cannot replace a slice of a MutableCollection with a slice of a smaller size")
603+
.code {
604+
var x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
605+
expectCrashLater()
606+
x.withUnsafeMutableBufferPointer { buffer in
607+
buffer[2..<6] = buffer[6..<8]
608+
}
609+
}
610+
591611
//===----------------------------------------------------------------------===//
592612
// isEmpty
593613
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)