@@ -70,6 +70,15 @@ class A<T> {
70
70
// expected-warning@-1 {{conditional cast from 'Self' to 'Self' always succeeds}}
71
71
// expected-warning@-2 {{conditional downcast from 'Self?' to 'A<T>' is equivalent to an implicit conversion to an optional 'A<T>'}}
72
72
}
73
+ func copy( ) -> Self {
74
+ let copy = Self . init ( a: 11 )
75
+ return copy
76
+ }
77
+
78
+ var copied : Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'A'?}}
79
+ let copy = Self . init ( a: 11 )
80
+ return copy
81
+ }
73
82
}
74
83
75
84
class B : A < Int > {
@@ -88,6 +97,14 @@ class B: A<Int> {
88
97
override class func y( ) {
89
98
print ( " override \( Self . self) . \( #function) " )
90
99
}
100
+ override func copy( ) -> Self {
101
+ let copy = super. copy ( ) as! Self // supported
102
+ return copy
103
+ }
104
+ override var copied : Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'B'?}}
105
+ let copy = super. copied as! Self // unsupported
106
+ return copy
107
+ }
91
108
}
92
109
93
110
class C {
@@ -121,6 +138,15 @@ struct S2 {
121
138
// expected-warning@-1 {{conditional cast from 'S2.S3<T>' to 'S2.S3<T>' always succeeds}}
122
139
}
123
140
}
141
+ func copy( ) -> Self {
142
+ let copy = Self . init ( )
143
+ return copy
144
+ }
145
+
146
+ var copied : Self {
147
+ let copy = Self . init ( )
148
+ return copy
149
+ }
124
150
}
125
151
126
152
extension S2 {
@@ -151,27 +177,3 @@ enum E {
151
177
return . e
152
178
}
153
179
}
154
-
155
- class A1 {
156
- required init ( ) { }
157
- func copy( ) -> Self {
158
- let copy = Self . init ( )
159
- return copy
160
- }
161
-
162
- var copied : Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'A1'?}}
163
- let copy = Self . init ( )
164
- return copy
165
- }
166
- }
167
-
168
- class B1 : A1 {
169
- override func copy( ) -> Self {
170
- let copy = super. copy ( ) as! Self // supported
171
- return copy
172
- }
173
- override var copied : Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'B1'?}}
174
- let copy = super. copied as! Self // unsupported
175
- return copy
176
- }
177
- }
0 commit comments