@@ -121,22 +121,133 @@ func barFunc() {
121
121
// https://github.com/apple/swift/issues/43464
122
122
123
123
class Aaron {
124
- init ( x: Int ) { }
125
- convenience init ( ) { init ( x: 1 ) } // expected-error {{missing 'self.' at initializer invocation}} {{24-24=self.}}
124
+ init ( x: Int ) {
125
+ func foo( ) {
126
+ // Make sure we recover and assume 'self.init'.
127
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{11-11=self.}}
128
+ // expected-error@+1 {{type of expression is ambiguous without a type annotation}}
129
+ _ = init
130
+ }
131
+ }
132
+ convenience init ( ) {
133
+ // Make sure we recover and assume 'self.init'.
134
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{5-5=self.}}
135
+ // expected-error@+1 {{cannot convert value of type 'Bool' to expected argument type 'Int'}}
136
+ init ( x: true )
137
+
138
+ // FIXME: self.init considered initializer delegation in nested function?
139
+ // expected-error@+2 {{initializer delegation ('self.init') cannot be nested in another expression}}
140
+ // expected-error@+1 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{22-22=self.}}
141
+ func foo( ) { _ = init ( ) }
142
+ }
143
+
144
+ required init ( y: Int ) { }
145
+
146
+ static func aaronFn( ) {
147
+ // Make sure we recover and assume 'self.init'.
148
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{9-9=self.}}
149
+ // expected-error@+1 {{incorrect argument label in call (have 'z:', expected 'y:')}}
150
+ _ = init ( z: 0 )
151
+ }
152
+
153
+ // Make sure we recover and assume 'self.init'.
154
+ // expected-error@+3 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{45-45=self.}}
155
+ // expected-error@+2 {{cannot convert value of type 'Aaron' to specified type 'Int'}}
156
+ // expected-error@+1 {{incorrect argument label in call (have 'z:', expected 'y:')}}
157
+ static var aaronVar : Aaron { let _: Int = init ( z: 0 ) }
126
158
}
127
159
128
160
class Theodosia : Aaron {
129
161
init ( ) {
130
- init ( x: 2 ) // expected-error {{missing 'super.' at initializer invocation}} {{5-5=super.}}
162
+ // Make sure we recover and assume 'super.init'.
163
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'super.'?}} {{5-5=super.}}
164
+ // expected-error@+1 {{cannot convert value of type 'Bool' to expected argument type 'Int'}}
165
+ init ( x: true )
166
+
167
+ // Make sure we recover and assume 'self.init'.
168
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{22-22=self.}}
169
+ // expected-error@+1 {{type of expression is ambiguous without a type annotation}}
170
+ func foo( ) { _ = init }
171
+ }
172
+
173
+ required init ( y: Int ) { }
174
+
175
+ static func theodosiaFn( ) {
176
+ // Make sure we recover and assume 'self.init'.
177
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{9-9=self.}}
178
+ // expected-error@+1 {{incorrect argument label in call (have 'z:', expected 'y:')}}
179
+ _ = init ( z: 0 )
180
+
181
+ // FIXME: We could optimistically parse this as an expression instead
182
+ // expected-error@+2 {{initializers may only be declared within a type}}
183
+ // expected-error@+1 {{expected parameter type following ':'}}
184
+ init ( z: 0 )
185
+ }
186
+
187
+ static var theodosiaVar : Aaron {
188
+ // Make sure we recover and assume 'self.init'.
189
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{9-9=self.}}
190
+ // expected-error@+1 {{incorrect argument label in call (have 'z:', expected 'y:')}}
191
+ _ = init ( z: 0 )
131
192
}
132
193
}
133
194
134
195
struct AaronStruct {
135
196
init ( x: Int ) { }
136
- init ( ) { init ( x: 1 ) } // expected-error {{missing 'self.' at initializer invocation}} {{12-12=self.}}
197
+ init ( ) {
198
+ // Make sure we recover and assume 'self.init'.
199
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{5-5=self.}}
200
+ // expected-error@+1 {{incorrect argument label in call (have 'y:', expected 'x:')}}
201
+ init ( y: 1 )
202
+
203
+ func foo( ) {
204
+ // Make sure we recover and assume 'self.init'.
205
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{11-11=self.}}
206
+ // expected-error@+1 {{incorrect argument label in call (have 'y:', expected 'x:')}}
207
+ _ = init ( y: 1 )
208
+ }
209
+ }
210
+
211
+ static func aaronFn( ) {
212
+ // Make sure we recover and assume 'self.init'.
213
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{9-9=self.}}
214
+ // expected-error@+1 {{incorrect argument label in call (have 'y:', expected 'x:')}}
215
+ _ = init ( y: 1 )
216
+
217
+ // FIXME: We could optimistically parse this as an expression instead
218
+ // expected-error@+2 {{initializers may only be declared within a type}}
219
+ // expected-error@+1 {{expected parameter type following ':'}}
220
+ init ( y: 1 )
221
+ }
222
+
223
+ static var aaronVar : Aaron {
224
+ // Make sure we recover and assume 'self.init'.
225
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{9-9=self.}}
226
+ // expected-error@+1 {{incorrect argument label in call (have 'y:', expected 'x:')}}
227
+ _ = init ( y: 1 )
228
+
229
+ // FIXME: We could optimistically parse this as an expression instead
230
+ // expected-error@+3 {{initializers may only be declared within a type}}
231
+ // expected-error@+2 {{consecutive statements on a line must be separated by ';'}}
232
+ // expected-error@+1 {{non-void function should return a value}}
233
+ return init ( )
234
+ }
137
235
}
138
236
139
237
enum AaronEnum : Int {
140
238
case A = 1
141
- init ( x: Int ) { init ( rawValue: x) ! } // expected-error {{missing 'self.' at initializer invocation}} {{18-18=self.}}
239
+
240
+ init ( x: Int ) {
241
+ // Make sure we recover and assume 'self.init'.
242
+ // expected-error@+2 {{initializer expression requires explicit access; did you mean to prepend it with 'self.'?}} {{5-5=self.}}
243
+ // expected-error@+1 {{cannot convert value of type 'String' to expected argument type 'Int'}}
244
+ init ( rawValue: " " ) !
245
+ }
246
+ }
247
+
248
+ do {
249
+ func foo( ) {
250
+ // expected-error@+1 {{initializer expression requires explicit access}} {none}}
251
+ _ = init ( )
252
+ }
142
253
}
0 commit comments