Skip to content

Commit 0ea4e3c

Browse files
committed
[stdlib] add availability annotations and tests
1 parent 3789ce2 commit 0ea4e3c

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

stdlib/public/core/MutableCollection.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ extension MutableCollection {
238238
/// the range must be valid indices of the collection.
239239
///
240240
/// - Complexity: O(1)
241+
@available(*, unavailable)
241242
@inlinable
242243
public subscript(bounds: Range<Index>) -> Slice<Self> {
243244
get {
@@ -282,7 +283,7 @@ extension MutableCollection {
282283
}
283284
}
284285

285-
@available(SwiftStdlib 5.5, *)
286+
@available(SwiftStdlib 9999, *)
286287
extension MutableCollection where SubSequence == Slice<Self> {
287288

288289
/// Accesses a contiguous subrange of the collection's elements.
@@ -310,6 +311,7 @@ extension MutableCollection where SubSequence == Slice<Self> {
310311
///
311312
/// - Complexity: O(1)
312313
@inlinable
314+
@_alwaysEmitIntoClient
313315
public subscript(bounds: Range<Index>) -> Slice<Self> {
314316
get {
315317
_failEarlyRangeCheck(bounds, bounds: startIndex..<endIndex)

validation-test/stdlib/CollectionDiagnostics.swift

+27
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,33 @@ struct MutableCollectionWithNonDefaultSubSequence: MutableCollection {
173173
}
174174
}
175175

176+
struct MutableCollectionWithDefaultSubSequence: MutableCollection {
177+
public var startIndex: Int
178+
public var endIndex: Int
179+
180+
public func index(after i: Int) -> Int { i+1 }
181+
public subscript(position: Int) -> Int {
182+
get { position }
183+
set { _ = newValue }
184+
}
185+
}
186+
187+
func subscriptMutableCollectionIgnored() {
188+
let cs: MutableCollectionWithNonDefaultSubSequence
189+
cs = .init(startIndex: 0, endIndex: 10)
190+
191+
let badSlice: Slice<MutableCollectionWithNonDefaultSubSequence>
192+
badSlice = cs[0..<2] // expected-error {{'subscript(_:)' is unavailable}}
193+
cs[3..<5] = badSlice // expected-error {{'subscript(_:)' is unavailable}}
194+
195+
let ds: MutableCollectionWithDefaultSubSequence
196+
ds = .init(startIndex: 0, endIndex: 10)
197+
198+
let goodSlice: Slice<MutableCollectionWithDefaultSubSequence>
199+
goodSlice = ds[0..<2]
200+
ds[3..<5] = goodSlice
201+
}
202+
176203
// FIXME: Remove -verify-ignore-unknown.
177204
// <unknown>:0: error: unexpected note produced: possibly intended match
178205
// <unknown>:0: error: unexpected note produced: possibly intended match

0 commit comments

Comments
 (0)