Skip to content

Commit 25378de

Browse files
committed
stdlib: make RangeReplaceableCollection.SubSequence a RangeReplaceableCollection
Fixes rdar://problem/28330668.
1 parent a6d1336 commit 25378de

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

stdlib/public/core/RangeReplaceableCollection.swift.gyb

+7
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ public protocol _RangeReplaceableIndexable : _Indexable {
244244
public protocol RangeReplaceableCollection
245245
: _RangeReplaceableIndexable, Collection
246246
{
247+
// FIXME(ABI): should require `RangeReplaceableCollection`.
248+
associatedtype SubSequence : _RangeReplaceableIndexable /*: RangeReplaceableCollection*/
249+
= RangeReplaceableSlice<Self>
250+
247251
//===--- Fundamental Requirements ---------------------------------------===//
248252

249253
/// Creates a new, empty collection.
@@ -540,6 +544,9 @@ public protocol RangeReplaceableCollection
540544
//===----------------------------------------------------------------------===//
541545

542546
extension RangeReplaceableCollection {
547+
public subscript(bounds: Range<Index>) -> RangeReplaceableSlice<Self> {
548+
return RangeReplaceableSlice(base: self, bounds: bounds)
549+
}
543550

544551
/// Creates a new collection containing the specified number of a single,
545552
/// repeated value.

validation-test/stdlib/CollectionDiagnostics.swift

+24
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,27 @@ struct BadBidirectionalIndexable : BidirectionalIndexable {
116116
// expected-error@+1 {{'index(after:)' has different argument names from those required by protocol '_BidirectionalIndexable' ('index(before:)'}}
117117
func index(after i: Int) -> Int { return 0 }
118118
}
119+
120+
//
121+
// Check that RangeReplaceableCollection.SubSequence is defaulted.
122+
//
123+
124+
struct RangeReplaceableCollection_SubSequence_IsDefaulted : RangeReplaceableCollection {
125+
var startIndex: Int { fatalError() }
126+
var endIndex: Int { fatalError() }
127+
128+
subscript(pos: Int) -> Int { return 0 }
129+
130+
func index(after: Int) -> Int { fatalError() }
131+
func index(before: Int) -> Int { fatalError() }
132+
func index(_: Int, offsetBy: Int) -> Int { fatalError() }
133+
func distance(from: Int, to: Int) -> Int { fatalError() }
134+
135+
mutating func replaceSubrange<C>(
136+
_ subrange: Range<Int>,
137+
with newElements: C
138+
) where C : Collection, C.Iterator.Element == Int {
139+
fatalError()
140+
}
141+
}
142+

0 commit comments

Comments
 (0)