@@ -70,6 +70,15 @@ class A<T> {
7070 // expected-warning@-1 {{conditional cast from 'Self' to 'Self' always succeeds}}
7171 // expected-warning@-2 {{conditional downcast from 'Self?' to 'A<T>' is equivalent to an implicit conversion to an optional 'A<T>'}}
7272 }
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+ }
7382}
7483
7584class B : A < Int > {
@@ -88,6 +97,14 @@ class B: A<Int> {
8897 override class func y( ) {
8998 print ( " override \( Self . self) . \( #function) " )
9099 }
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+ }
91108}
92109
93110class C {
@@ -121,6 +138,15 @@ struct S2 {
121138 // expected-warning@-1 {{conditional cast from 'S2.S3<T>' to 'S2.S3<T>' always succeeds}}
122139 }
123140 }
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+ }
124150}
125151
126152extension S2 {
@@ -151,27 +177,3 @@ enum E {
151177 return . e
152178 }
153179}
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