Skip to content

Commit ecf94f5

Browse files
committed
Merge pull request #2677 from natecook1000/nc-mutslice-error
[stdlib] Fix _writeBackMutableSlice error messages
2 parents 239b5e0 + 089ea92 commit ecf94f5

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
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: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ struct MinimalCollectionWith${Implementation}Filter<Element>
112112
}
113113

114114
func filter(
115-
@noescape _ transform: (Element) throws -> Bool
115+
_ transform: @noescape (Element) throws -> Bool
116116
) rethrows -> [Element] {
117117
MinimalCollectionWithCustomFilter.timesFilterWasCalled += 1
118118
return try _data.filter(transform)
@@ -126,7 +126,7 @@ struct MinimalCollectionWith${Implementation}Filter<Element>
126126

127127
func callStaticCollectionFilter(
128128
_ sequence: MinimalCollectionWithDefaultFilter<OpaqueValue<Int>>,
129-
@noescape includeElement: (OpaqueValue<Int>) -> Bool
129+
includeElement: @noescape (OpaqueValue<Int>) -> Bool
130130
) -> [OpaqueValue<Int>] {
131131
var result = sequence.filter(includeElement)
132132
expectType([OpaqueValue<Int>].self, &result)
@@ -135,7 +135,7 @@ func callStaticCollectionFilter(
135135

136136
func callStaticCollectionFilter(
137137
_ sequence: MinimalCollectionWithCustomFilter<OpaqueValue<Int>>,
138-
@noescape includeElement: (OpaqueValue<Int>) -> Bool
138+
includeElement: @noescape (OpaqueValue<Int>) -> Bool
139139
) -> [OpaqueValue<Int>] {
140140
var result = sequence.filter(includeElement)
141141
expectType([OpaqueValue<Int>].self, &result)
@@ -144,7 +144,7 @@ func callStaticCollectionFilter(
144144

145145
func callGenericCollectionFilter<S : Collection>(
146146
_ sequence: S,
147-
@noescape includeElement: (S.Iterator.Element) -> Bool
147+
includeElement: @noescape (S.Iterator.Element) -> Bool
148148
) -> [S.Iterator.Element] {
149149
var result = sequence.filter(includeElement)
150150
expectType(Array<S.Iterator.Element>.self, &result)
@@ -249,7 +249,7 @@ struct MinimalCollectionWith${Implementation}Map<Element>
249249
}
250250

251251
func map<T>(
252-
@noescape _ transform: (Element) throws -> T
252+
_ transform: @noescape (Element) throws -> T
253253
) rethrows -> [T] {
254254
MinimalCollectionWithCustomMap.timesMapWasCalled += 1
255255
return try _data.map(transform)
@@ -263,7 +263,7 @@ struct MinimalCollectionWith${Implementation}Map<Element>
263263

264264
func callStaticCollectionMap<T>(
265265
_ collection: MinimalCollectionWithDefaultMap<OpaqueValue<Int>>,
266-
@noescape transform: (OpaqueValue<Int>) -> T
266+
transform: @noescape (OpaqueValue<Int>) -> T
267267
) -> [T] {
268268
var result = collection.map(transform)
269269
expectType([T].self, &result)
@@ -272,7 +272,7 @@ func callStaticCollectionMap<T>(
272272

273273
func callStaticCollectionMap<T>(
274274
_ collection: MinimalCollectionWithCustomMap<OpaqueValue<Int>>,
275-
@noescape transform: (OpaqueValue<Int>) -> T
275+
transform: @noescape (OpaqueValue<Int>) -> T
276276
) -> [T] {
277277
var result = collection.map(transform)
278278
expectType([T].self, &result)
@@ -281,7 +281,7 @@ func callStaticCollectionMap<T>(
281281

282282
func callGenericCollectionMap<C : Collection, T>(
283283
_ collection: C,
284-
@noescape transform: (C.Iterator.Element) -> T
284+
transform: @noescape (C.Iterator.Element) -> T
285285
) -> [T] {
286286
var result = collection.map(transform)
287287
expectType([T].self, &result)
@@ -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
//===----------------------------------------------------------------------===//
@@ -730,7 +750,7 @@ CollectionTypeTests.test("index(of:)/ContinueSearch") {
730750

731751
CollectionTypeTests.test("Collection/split/dispatch") {
732752
var tester = CollectionLog.dispatchTester([OpaqueValue(1)])
733-
tester.split { $0.value == 1 }
753+
_ = tester.split { $0.value == 1 }
734754
expectCustomizable(tester, tester.log.split)
735755
}
736756

@@ -740,7 +760,7 @@ CollectionTypeTests.test("Collection/split/dispatch") {
740760

741761
CollectionTypeTests.test("Collection/prefix(through:)/dispatch") {
742762
var tester = CollectionLog.dispatchTester([1, 2, 3].map(OpaqueValue.init))
743-
tester.prefix(through: 1)
763+
_ = tester.prefix(through: 1)
744764
expectCustomizable(tester, tester.log.prefixThrough)
745765
}
746766

@@ -750,7 +770,7 @@ CollectionTypeTests.test("Collection/prefix(through:)/dispatch") {
750770

751771
CollectionTypeTests.test("Collection/prefix(upTo:)/dispatch") {
752772
var tester = CollectionLog.dispatchTester([OpaqueValue(1)])
753-
tester.prefix(upTo: 1)
773+
_ = tester.prefix(upTo: 1)
754774
expectCustomizable(tester, tester.log.prefixUpTo)
755775
}
756776

@@ -760,7 +780,7 @@ CollectionTypeTests.test("Collection/prefix(upTo:)/dispatch") {
760780

761781
CollectionTypeTests.test("Collection/suffix(from:)/dispatch") {
762782
var tester = CollectionLog.dispatchTester([1, 2, 3].map(OpaqueValue.init))
763-
tester.suffix(from: 1)
783+
_ = tester.suffix(from: 1)
764784
expectCustomizable(tester, tester.log.suffixFrom)
765785
}
766786

0 commit comments

Comments
 (0)