Skip to content

Commit

Permalink
StdlibUnittest: make isSequenceType and expectCollectionType more strict
Browse files Browse the repository at this point in the history
These constraints should be on the SequenceType and CollectionType
protocols, but we can't express them in the language today.

Swift SVN r32295
  • Loading branch information
gribozavr committed Sep 29, 2015
1 parent 7afb88f commit b41986e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions stdlib/private/StdlibUnittest/StdlibUnittest.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,22 @@ public func expectGE(lhs: Int, _ rhs: Int, ${TRACE}) {
public func expectType<T>(_: T.Type, inout _ x: T) {}
public func expectEqualType<T>(_: T.Type, _: T.Type) {}

public func isSequenceType<X : SequenceType>(x: X) -> X { return x }
public func isSequenceType<
X : SequenceType
where
X.SubSequence : SequenceType,
X.SubSequence.Generator.Element == X.Generator.Element,
X.SubSequence.SubSequence == X.SubSequence
>(x: X) -> X { return x }

public func expectIndexable<X : Indexable>(x: X) -> X { return x }
public func expectCollectionType<X : CollectionType>(x: X) -> X { return x }
public func expectCollectionType<
X : CollectionType
where
X.SubSequence : CollectionType,
X.SubSequence.Generator.Element == X.Generator.Element,
X.SubSequence.SubSequence == X.SubSequence
>(x: X) -> X { return x }

/// A slice is a `CollectionType` that when sliced returns an instance of
/// itself.
Expand Down

0 comments on commit b41986e

Please sign in to comment.