Skip to content

Deprecate the Indexable protocols #4091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stdlib/public/core/BidirectionalCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `BidirectionalCollection` protocol instead, because it has a more complete
/// interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
public protocol BidirectionalIndexable : Indexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
3 changes: 3 additions & 0 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
///
/// In most cases, it's best to ignore this protocol and use the `Collection`
/// protocol instead, because it has a more complete interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
public protocol IndexableBase {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down Expand Up @@ -156,6 +157,7 @@ public protocol IndexableBase {
///
/// In most cases, it's best to ignore this protocol and use the `Collection`
/// protocol instead, because it has a more complete interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
public protocol Indexable : IndexableBase {
/// A type used to represent the number of steps between two indices, where
/// one value is reachable from the other.
Expand Down Expand Up @@ -1703,3 +1705,4 @@ extension Collection where Iterator.Element : Equatable {

@available(*, unavailable, message: "PermutationGenerator has been removed in Swift 3")
public struct PermutationGenerator<C : Collection, Indices : Sequence> {}

1 change: 1 addition & 0 deletions stdlib/public/core/MutableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `MutableCollection` protocol instead, because it has a more complete
/// interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'MutableCollection' instead")
public protocol MutableIndexable : Indexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/RandomAccessCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `RandomAccessCollection` protocol instead, because it has a more complete
/// interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
public protocol RandomAccessIndexable : BidirectionalIndexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/RangeReplaceableCollection.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/// In most cases, it's best to ignore this protocol and use the
/// `RangeReplaceableCollection` protocol instead, because it has a more
/// complete interface.
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'RandomAccessCollection' instead")
public protocol RangeReplaceableIndexable : Indexable {
// FIXME(ABI)(compiler limitation): there is no reason for this protocol
// to exist apart from missing compiler features that we emulate with it.
Expand Down
7 changes: 6 additions & 1 deletion validation-test/stdlib/CollectionDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func sortResultIgnored<
array.sorted { $0 < $1 } // expected-warning {{result of call to 'sorted(by:)' is unused}}
}

struct GoodIndexable : Indexable {
// expected-warning@+1 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
struct GoodIndexable : Indexable {
func index(after i: Int) -> Int { return i + 1 }
var startIndex: Int { return 0 }
var endIndex: Int { return 0 }
Expand All @@ -64,6 +65,7 @@ struct GoodIndexable : Indexable {
}


// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
// expected-error@+1 {{type 'BadIndexable1' does not conform to protocol 'IndexableBase'}}
struct BadIndexable1 : Indexable {
func index(after i: Int) -> Int { return i + 1 }
Expand All @@ -75,6 +77,7 @@ struct BadIndexable1 : Indexable {
// Missing 'subscript(_:) -> SubSequence'.
}

// expected-warning@+2 {{'Indexable' is deprecated: it will be removed in Swift 4.0. Please use 'Collection' instead}}
// expected-error@+1 {{type 'BadIndexable2' does not conform to protocol 'IndexableBase'}}
struct BadIndexable2 : Indexable {
var startIndex: Int { return 0 }
Expand All @@ -85,6 +88,7 @@ struct BadIndexable2 : Indexable {
// Missing index(after:) -> Int
}

// expected-warning@+1 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead}}
struct GoodBidirectionalIndexable1 : BidirectionalIndexable {
var startIndex: Int { return 0 }
var endIndex: Int { return 0 }
Expand All @@ -97,6 +101,7 @@ struct GoodBidirectionalIndexable1 : BidirectionalIndexable {

// We'd like to see: {{type 'BadBidirectionalIndexable' does not conform to protocol 'BidirectionalIndexable'}}
// But the compiler doesn't generate that error.
// expected-warning@+1 {{'BidirectionalIndexable' is deprecated: it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead}}
struct BadBidirectionalIndexable : BidirectionalIndexable {
var startIndex: Int { return 0 }
var endIndex: Int { return 0 }
Expand Down