Files
swift-mirror/test/1_stdlib/CollectionDiagnostics.swift
Dmitri Hrybenko 0ef360228b stdlib: constrain CollectionType.SubSlice to _CollectionDefaultsType
The language has limitations that don't allow us to express the API we
actually want, and we have to resort to underscored protocols again.

<rdar://problem/20715009> Implement recursive protocol constraints

<rdar://problem/20477576> 'where' constraints on associated types in
protocols

Swift SVN r27820
2015-04-27 21:50:19 +00:00

39 lines
986 B
Swift

// RUN: %target-parse-verify-swift
import StdlibUnittest
//
// Check that CollectionType._prext_SubSlice is constrained to CollectionType.
//
// expected-error@+1 {{type 'CollectionWithBadSubSlice' does not conform to protocol 'CollectionType'}}
struct CollectionWithBadSubSlice : CollectionType {
var startIndex: MinimalForwardIndex {
fatalError("unreachable")
}
var endIndex: MinimalForwardIndex {
fatalError("unreachable")
}
subscript(i: MinimalForwardIndex) -> OpaqueValue<Int> {
fatalError("unreachable")
}
// expected-note@+1 {{possibly intended match '_prext_SubSlice' does not conform to '_CollectionDefaultsType'}}
typealias _prext_SubSlice = OpaqueValue<Int8>
}
func useCollectionTypeSubSliceIndex<
C : CollectionType
where
C._prext_SubSlice.Index : BidirectionalIndexType
>(c: C) {}
func useCollectionTypeSubSliceGeneratorElement<
C : CollectionType
where
C._prext_SubSlice.Generator.Element == C.Generator.Element
>(c: C) {}