@@ -256,6 +256,167 @@ final class ExpressionTests: ParserTestCase {
256
256
)
257
257
}
258
258
259
+ func testKeyPathMethodAndInitializers( ) {
260
+ assertParse (
261
+ #"\Foo.method()"# ,
262
+ substructure: KeyPathExprSyntax (
263
+ root: TypeSyntax ( " Foo " ) ,
264
+ components: KeyPathComponentListSyntax ( [
265
+ KeyPathComponentSyntax (
266
+ period: . periodToken( ) ,
267
+ component: KeyPathComponentSyntax . Component (
268
+ KeyPathMethodComponentSyntax (
269
+ declName: DeclReferenceExprSyntax ( baseName: . identifier( " method " ) ) ,
270
+ leftParen: . leftParenToken( ) ,
271
+ arguments: LabeledExprListSyntax ( [ ] ) ,
272
+ rightParen: . rightParenToken( )
273
+ )
274
+ )
275
+ )
276
+ ] )
277
+ ) ,
278
+ experimentalFeatures: . keypathWithMethodMembers
279
+ )
280
+
281
+ assertParse (
282
+ #"\Foo.method(10)"# ,
283
+ substructure: KeyPathExprSyntax (
284
+ root: TypeSyntax ( " Foo " ) ,
285
+ components: KeyPathComponentListSyntax ( [
286
+ KeyPathComponentSyntax (
287
+ period: . periodToken( ) ,
288
+ component: . init(
289
+ KeyPathMethodComponentSyntax (
290
+ declName: DeclReferenceExprSyntax ( baseName: . identifier( " method " ) ) ,
291
+ leftParen: . leftParenToken( ) ,
292
+ arguments: LabeledExprListSyntax ( [
293
+ LabeledExprSyntax (
294
+ label: nil ,
295
+ colon: nil ,
296
+ expression: ExprSyntax ( " 10 " )
297
+ )
298
+ ] ) ,
299
+ rightParen: . rightParenToken( )
300
+ )
301
+ )
302
+ )
303
+ ] )
304
+ ) ,
305
+ experimentalFeatures: . keypathWithMethodMembers
306
+ )
307
+
308
+ assertParse (
309
+ #"\Foo.method(arg: 10)"# ,
310
+ substructure: KeyPathExprSyntax (
311
+ root: TypeSyntax ( " Foo " ) ,
312
+ components: KeyPathComponentListSyntax ( [
313
+ KeyPathComponentSyntax (
314
+ period: . periodToken( ) ,
315
+ component: . init(
316
+ KeyPathMethodComponentSyntax (
317
+ declName: DeclReferenceExprSyntax ( baseName: . identifier( " method " ) ) ,
318
+ leftParen: . leftParenToken( ) ,
319
+ arguments: LabeledExprListSyntax ( [
320
+ LabeledExprSyntax (
321
+ label: . identifier( " arg " ) ,
322
+ colon: . colonToken( ) ,
323
+ expression: ExprSyntax ( " 10 " )
324
+ )
325
+ ] ) ,
326
+ rightParen: . rightParenToken( )
327
+ )
328
+ )
329
+ )
330
+ ] )
331
+ ) ,
332
+ experimentalFeatures: . keypathWithMethodMembers
333
+ )
334
+
335
+ assertParse (
336
+ #"\Foo.method().anotherMethod(arg: 10)"# ,
337
+ substructure: KeyPathExprSyntax (
338
+ root: TypeSyntax ( " Foo " ) ,
339
+ components: KeyPathComponentListSyntax ( [
340
+ KeyPathComponentSyntax (
341
+ period: . periodToken( ) ,
342
+ component: . init(
343
+ KeyPathMethodComponentSyntax (
344
+ declName: DeclReferenceExprSyntax ( baseName: . identifier( " method " ) ) ,
345
+ leftParen: . leftParenToken( ) ,
346
+ arguments: LabeledExprListSyntax ( [ ] ) ,
347
+ rightParen: . rightParenToken( )
348
+ )
349
+ )
350
+ ) ,
351
+ KeyPathComponentSyntax (
352
+ period: . periodToken( ) ,
353
+ component: . init(
354
+ KeyPathMethodComponentSyntax (
355
+ declName: DeclReferenceExprSyntax ( baseName: . identifier( " anotherMethod " ) ) ,
356
+ leftParen: . leftParenToken( ) ,
357
+ arguments: LabeledExprListSyntax ( [
358
+ LabeledExprSyntax (
359
+ label: . identifier( " arg " ) ,
360
+ colon: . colonToken( ) ,
361
+ expression: ExprSyntax ( " 10 " )
362
+ )
363
+ ] ) ,
364
+ rightParen: . rightParenToken( )
365
+ )
366
+ )
367
+ ) ,
368
+ ] )
369
+ ) ,
370
+ experimentalFeatures: . keypathWithMethodMembers
371
+ )
372
+
373
+ assertParse (
374
+ #"\Foo.Type.init()"# ,
375
+ substructure: KeyPathExprSyntax (
376
+ root: TypeSyntax (
377
+ MetatypeTypeSyntax ( baseType: TypeSyntax ( " Foo " ) , metatypeSpecifier: . keyword( . Type) )
378
+ ) ,
379
+ components: KeyPathComponentListSyntax ( [
380
+ KeyPathComponentSyntax (
381
+ period: . periodToken( ) ,
382
+ component: KeyPathComponentSyntax . Component (
383
+ KeyPathMethodComponentSyntax (
384
+ declName: DeclReferenceExprSyntax ( baseName: . keyword( . init( " init " ) !) ) ,
385
+ leftParen: . leftParenToken( ) ,
386
+ arguments: LabeledExprListSyntax ( [ ] ) ,
387
+ rightParen: . rightParenToken( )
388
+ )
389
+ )
390
+ )
391
+ ] )
392
+ ) ,
393
+ experimentalFeatures: . keypathWithMethodMembers
394
+ )
395
+
396
+ assertParse (
397
+ #"""
398
+ \Foo.method(1️⃣
399
+ """# ,
400
+ diagnostics: [
401
+ DiagnosticSpec (
402
+ message: " expected value and ')' to end key path method component " ,
403
+ fixIts: [ " insert value and ')' " ]
404
+ )
405
+ ] ,
406
+ fixedSource: #"\Foo.method(<#expression#>)"# ,
407
+ experimentalFeatures: . keypathWithMethodMembers
408
+ )
409
+
410
+ assertParse (
411
+ #"\Foo.1️⃣()"# ,
412
+ diagnostics: [
413
+ DiagnosticSpec ( message: " expected identifier in key path method component " , fixIts: [ " insert identifier " ] )
414
+ ] ,
415
+ fixedSource: #"\Foo.<#identifier#>()"# ,
416
+ experimentalFeatures: . keypathWithMethodMembers
417
+ )
418
+ }
419
+
259
420
func testKeyPathSubscript( ) {
260
421
assertParse (
261
422
#"\Foo.Type.[2]"# ,
0 commit comments