-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathnested_generics.swift
53 lines (41 loc) · 1.13 KB
/
nested_generics.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// RUN: %swift -parse -verify %s
struct G<T> {
init() {}
init<U>(x:G<U>) { }
func foo<U>(x: G<U>) { }
func bar<U>(x: U) { }
static func static_foo<U>(x: G<U>) { }
static func static_bar<U>(x: U) { }
}
typealias GInt = G<Int>
typealias GChar = G<UnicodeScalar>
GInt(x: GChar())
GInt().foo(GChar())
GInt().bar(0)
GInt.static_foo(GChar())
GInt.static_bar(0)
// <rdar://problem/12895793>
struct AnyStream<T : SequenceType> {
struct StreamRange<S : GeneratorType> { // expected-error{{generic type 'StreamRange' nested}}
var index : Int
var elements : S
// Conform to the GeneratorType protocol.
typealias Element = (Int, S.Element)
mutating
func next() -> Element? {
var result = (index, elements.next())
if result.1 == nil { return .None }
++index
return (result.0, result.1!)
}
}
var input : T
// Conform to the enumerable protocol.
typealias Elements = StreamRange<T.Generator>
func getElements() -> Elements {
return Elements(index: 0, elements: input.generate())
}
}
func enumerate<T : SequenceType>(arg: T) -> AnyStream<T> {
return AnyStream<T>(input: arg)
}