forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nested.swift
85 lines (69 loc) · 2.82 KB
/
nested.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// RUN: %target-parse-verify-swift
struct OuterNonGeneric { // ok
struct MidNonGeneric { // ok
struct InnerNonGeneric {} // ok
struct InnerGeneric<A> {} // expected-error{{generic type 'InnerGeneric' nested in type 'OuterNonGeneric.MidNonGeneric'}}
}
struct MidGeneric<B> { // expected-error{{generic type 'MidGeneric' nested in type 'OuterNonGeneric'}}
struct InnerNonGeneric {} // expected-error{{type 'InnerNonGeneric' nested in generic type 'OuterNonGeneric.MidGeneric'}}
struct InnerGeneric<C> {} // expected-error{{generic type 'InnerGeneric' nested in type 'OuterNonGeneric.MidGeneric'}}
func flock(b: B) {}
}
}
struct OuterGeneric<D> {
struct MidNonGeneric { // expected-error{{type 'MidNonGeneric' nested in generic type 'OuterGeneric'}}
struct InnerNonGeneric {} // expected-error{{type 'InnerNonGeneric' nested in generic type 'OuterGeneric<D>.MidNonGeneric'}}
struct InnerGeneric<E> {} // expected-error{{generic type 'InnerGeneric' nested in type 'OuterGeneric<D>.MidNonGeneric'}}
func roost(d: D) {}
}
struct MidGeneric<F> { // expected-error{{generic type 'MidGeneric' nested in type 'OuterGeneric'}}
struct InnerNonGeneric {} // expected-error{{type 'InnerNonGeneric' nested in generic type 'OuterGeneric<D>.MidGeneric'}}
struct InnerGeneric<G> {} // expected-error{{generic type 'InnerGeneric' nested in type 'OuterGeneric<D>.MidGeneric'}}
func nest(d: D, f: F) {}
}
protocol InnerProtocol { // expected-error{{declaration is only valid at file scope}}
typealias Rooster
func flip(r: Rooster)
func flop(t: D)
}
}
class OuterNonGenericClass {
enum InnerNonGeneric {
case Baz
case Zab
}
}
class OuterGenericClass<T> {
enum InnerNonGeneric { // expected-error {{type 'InnerNonGeneric' nested in generic type 'OuterGenericClass' is not allowed}}
case Baz
case Zab
}
protocol InnerProtocol { // expected-error{{declaration is only valid at file scope}}
typealias Rooster
func flip(r: Rooster)
func flop(t: T)
}
class InnerNonGenericClass : InnerNonGenericBase {} // expected-error {{type 'InnerNonGenericClass' nested in generic type 'OuterGenericClass' is not allowed}}
class InnerNonGenericBase {} // expected-error {{type 'InnerNonGenericBase' nested in generic type 'OuterGenericClass' is not allowed}}
}
protocol OuterProtocol {
typealias Hen
protocol InnerProtocol { // expected-error{{type not allowed here}}
typealias Rooster
func flip(r: Rooster)
func flop(h: Hen)
}
}
protocol Racoon {
typealias Stripes
class Claw<T> { // expected-error{{type not allowed here}}
func mangle(s: Stripes) {}
}
struct Fang<T> { // expected-error{{type not allowed here}}
func gnaw(s: Stripes) {}
}
}
enum OuterEnum {
protocol C {} // expected-error{{declaration is only valid at file scope}}
case C(C)
}