Skip to content

Commit e43b009

Browse files
authored
Merge pull request #10317 from phausler/swift-4.0-branch-indexpath_dropFirst_1ary
[Foundation] 1-ary IndexPath forms invalid range on slices
2 parents 2d34fe4 + 1a711a3 commit e43b009

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

stdlib/public/SDK/Foundation/IndexPath.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,8 @@ public struct IndexPath : ReferenceConvertible, Equatable, Hashable, MutableColl
257257
}
258258
case .single(let index):
259259
switch (range.lowerBound, range.upperBound) {
260-
case (0, 0):
260+
case (0, 0): fallthrough
261+
case (1, 1):
261262
return .empty
262263
case (0, 1):
263264
return .single(index)

test/stdlib/TestIndexPath.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,15 @@ class TestIndexPath: TestIndexPathSuper {
711711
func test_unconditionallyBridgeFromObjectiveC() {
712712
expectEqual(IndexPath(), IndexPath._unconditionallyBridgeFromObjectiveC(nil))
713713
}
714+
715+
func test_slice_1ary() {
716+
let indexPath: IndexPath = [0]
717+
let res = indexPath.dropFirst()
718+
expectEqual(0, res.count)
719+
720+
let slice = indexPath[1..<1]
721+
expectEqual(0, slice.count)
722+
}
714723
}
715724

716725
#if !FOUNDATION_XCTEST
@@ -762,5 +771,6 @@ IndexPathTests.test("testObjcBridgeType") { TestIndexPath().testObjcBridgeType()
762771
IndexPathTests.test("test_AnyHashableContainingIndexPath") { TestIndexPath().test_AnyHashableContainingIndexPath() }
763772
IndexPathTests.test("test_AnyHashableCreatedFromNSIndexPath") { TestIndexPath().test_AnyHashableCreatedFromNSIndexPath() }
764773
IndexPathTests.test("test_unconditionallyBridgeFromObjectiveC") { TestIndexPath().test_unconditionallyBridgeFromObjectiveC() }
774+
IndexPathTests.test("test_slice_1ary") { TestIndexPath().test_slice_1ary() }
765775
runAllTests()
766776
#endif

0 commit comments

Comments
 (0)