Skip to content

Commit 1c390bc

Browse files
authored
Merge pull request swiftlang#9846 from apple/remove-redundant-slicing
2 parents b651cfe + 0016379 commit 1c390bc

File tree

2 files changed

+1
-100
lines changed

2 files changed

+1
-100
lines changed

stdlib/public/core/CollectionAlgorithms.swift.gyb

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -466,106 +466,6 @@ ${orderingExplanation}
466466
}
467467
}
468468

469-
% for Self in '_Indexable', '_MutableIndexable':
470-
%{
471-
472-
subscriptCommentPre = """\
473-
/// Accesses a contiguous subrange of the collection's elements.
474-
///
475-
/// The accessed slice uses the same indices for the same elements as the
476-
/// original collection. Always use the slice's `startIndex` property
477-
/// instead of assuming that its indices start at a particular value.
478-
///
479-
/// This example demonstrates getting a slice of an array of strings, finding
480-
/// the index of one of the strings in the slice, and then using that index
481-
/// in the original array.
482-
///
483-
/// let streets = ["Adams", "Bryant", "Channing", "Douglas", "Evarts"]
484-
/// let streetsSlice = streets[2 ..< streets.endIndex]
485-
/// print(streetsSlice)
486-
/// // Prints "["Channing", "Douglas", "Evarts"]"
487-
///
488-
/// let index = streetsSlice.index(of: "Evarts") // 4"""
489-
490-
if 'Mutable' in Self:
491-
subscriptCommentMid = """\
492-
/// streets[index!] = "Eustace"
493-
/// print(streets[index!])
494-
/// // Prints "Eustace\""""
495-
else:
496-
subscriptCommentMid = """\
497-
/// print(streets[index!])
498-
/// // Prints "Evarts\""""
499-
500-
subscriptCommentPost = """\
501-
///
502-
/// - Parameter bounds: A range of the collection's indices. The bounds of
503-
/// the range must be valid indices of the collection."""
504-
}%
505-
// FIXME(ABI)#180 (Type checker)
506-
// WORKAROUND rdar://25214066 - should be on Collection
507-
extension ${Self} {
508-
${subscriptCommentPre}
509-
${subscriptCommentMid}
510-
${subscriptCommentPost}
511-
@_inlineable
512-
public subscript(bounds: ClosedRange<Index>) -> SubSequence {
513-
get {
514-
return self[
515-
Range(
516-
uncheckedBounds: (
517-
lower: bounds.lowerBound,
518-
upper: index(after: bounds.upperBound)))
519-
]
520-
}
521-
% if 'Mutable' in Self:
522-
set {
523-
self[
524-
Range(
525-
uncheckedBounds: (
526-
lower: bounds.lowerBound,
527-
upper: index(after: bounds.upperBound)))
528-
] = newValue
529-
}
530-
% end
531-
}
532-
}
533-
534-
// FIXME(ABI)#180 (Type checker)
535-
// WORKAROUND rdar://25214066 - should be on Collection
536-
extension ${Self} where Index : Strideable, Index.Stride : SignedInteger {
537-
${subscriptCommentPre}
538-
${subscriptCommentMid}
539-
${subscriptCommentPost}
540-
@_inlineable
541-
public subscript(bounds: CountableRange<Index>) -> SubSequence {
542-
get {
543-
return self[Range(bounds)]
544-
}
545-
% if 'Mutable' in Self:
546-
set {
547-
self[Range(bounds)] = newValue
548-
}
549-
% end
550-
}
551-
552-
${subscriptCommentPre}
553-
${subscriptCommentMid}
554-
${subscriptCommentPost}
555-
@_inlineable
556-
public subscript(bounds: CountableClosedRange<Index>) -> SubSequence {
557-
get {
558-
return self[ClosedRange(bounds)]
559-
}
560-
% if 'Mutable' in Self:
561-
set {
562-
self[ClosedRange(bounds)] = newValue
563-
}
564-
% end
565-
}
566-
}
567-
% end
568-
569469
//===--- Unavailable stuff ------------------------------------------------===//
570470

571471
extension MutableCollection where Self : RandomAccessCollection {

test/stdlib/RangeDiagnostics.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ func disallowSubscriptingOnIntegers() {
298298

299299
r0[0...4] // expected-error {{ambiguous use of 'subscript'}}
300300
r1[0...4] // expected-error {{ambiguous use of 'subscript'}}
301+
301302
r2[0...4] // expected-error {{cannot subscript a value of type 'CountableClosedRange<Int>' with an index of type 'CountableClosedRange<Int>'}}
302303
r3[0...4] // expected-error {{cannot subscript a value of type 'CountableClosedRange<UInt>' with an index of type 'CountableClosedRange<Int>'}}
303304
(10...100)[0...4] // expected-error {{cannot subscript a value of type 'CountableClosedRange<Int>' with an index of type 'CountableClosedRange<Int>'}}

0 commit comments

Comments
 (0)