@@ -2315,36 +2315,27 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2315
2315
if (FD->getName ().empty ())
2316
2316
return ;
2317
2317
foundFunction (FD);
2318
- bool IsImplicitlyCurriedInstanceMethod =
2319
- isImplicitlyCurriedInstanceMethod (FD);
2320
2318
2321
2319
StringRef Name = FD->getName ().get ();
2322
2320
assert (!Name.empty () && " name should not be empty" );
2323
2321
2324
2322
Type FunctionType = getTypeOfMember (FD);
2325
2323
assert (FunctionType);
2326
2324
2327
- unsigned NumParamLists;
2325
+ auto AFT = FunctionType->getAs <AnyFunctionType>();
2326
+
2327
+ bool IsImplicitlyCurriedInstanceMethod = false ;
2328
2328
if (FD->hasImplicitSelfDecl ()) {
2329
- if (IsImplicitlyCurriedInstanceMethod)
2330
- NumParamLists = 2 ;
2331
- else {
2332
- NumParamLists = 1 ;
2329
+ IsImplicitlyCurriedInstanceMethod = isImplicitlyCurriedInstanceMethod (FD);
2333
2330
2334
- // Strip off 'self'
2335
- if (FunctionType->is <AnyFunctionType>())
2336
- FunctionType = FunctionType->castTo <AnyFunctionType>()->getResult ();
2337
- }
2338
- } else {
2339
- NumParamLists = 1 ;
2331
+ // Strip off '(_ self: Self)' if needed.
2332
+ if (AFT && !IsImplicitlyCurriedInstanceMethod)
2333
+ AFT = AFT->getResult ()->getAs <AnyFunctionType>();
2340
2334
}
2341
2335
2342
2336
bool trivialTrailingClosure = false ;
2343
- if (!IsImplicitlyCurriedInstanceMethod &&
2344
- FunctionType->is <AnyFunctionType>()) {
2345
- trivialTrailingClosure = hasTrivialTrailingClosure (
2346
- FD, FunctionType->castTo <AnyFunctionType>());
2347
- }
2337
+ if (AFT && !IsImplicitlyCurriedInstanceMethod)
2338
+ trivialTrailingClosure = hasTrivialTrailingClosure (FD, AFT);
2348
2339
2349
2340
// Add the method, possibly including any default arguments.
2350
2341
auto addMethodImpl = [&](bool includeDefaultArgs = true ,
@@ -2364,14 +2355,13 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2364
2355
2365
2356
llvm::SmallString<32 > TypeStr;
2366
2357
2367
- if (!FunctionType-> is <AnyFunctionType>() ) {
2358
+ if (!AFT ) {
2368
2359
llvm::raw_svector_ostream OS (TypeStr);
2369
2360
FunctionType.print (OS);
2370
2361
Builder.addTypeAnnotation (OS.str ());
2371
2362
return ;
2372
2363
}
2373
2364
2374
- auto AFT = FunctionType->castTo <AnyFunctionType>();
2375
2365
if (IsImplicitlyCurriedInstanceMethod) {
2376
2366
Builder.addLeftParen ();
2377
2367
addCallArgumentPatterns (Builder, AFT->getParams (),
@@ -2380,6 +2370,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2380
2370
Builder.addRightParen ();
2381
2371
} else if (trivialTrailingClosure) {
2382
2372
Builder.addBraceStmtWithCursor (" { code }" );
2373
+ addThrows (Builder, AFT, FD);
2383
2374
} else {
2384
2375
Builder.addLeftParen ();
2385
2376
addCallArgumentPatterns (Builder, AFT, FD->getParameters (),
@@ -2393,11 +2384,12 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2393
2384
// Build type annotation.
2394
2385
{
2395
2386
llvm::raw_svector_ostream OS (TypeStr);
2396
- for ( unsigned i = 0 ; i < NumParamLists - 1 ; ++i ) {
2387
+ if (IsImplicitlyCurriedInstanceMethod ) {
2397
2388
ResultType->castTo <AnyFunctionType>()->printParams (OS);
2398
2389
ResultType = ResultType->castTo <AnyFunctionType>()->getResult ();
2399
2390
OS << " -> " ;
2400
2391
}
2392
+
2401
2393
// What's left is the result type.
2402
2394
if (ResultType->isVoid ()) {
2403
2395
OS << " Void" ;
@@ -2417,15 +2409,16 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
2417
2409
Builder.addTypeAnnotation (TypeStr);
2418
2410
};
2419
2411
2420
- if (FunctionType->is <AnyFunctionType>() &&
2421
- hasInterestingDefaultValues (FD)) {
2422
- addMethodImpl (/* includeDefaultArgs*/ false );
2423
- }
2424
- if (trivialTrailingClosure) {
2425
- addMethodImpl (/* includeDefaultArgs=*/ false ,
2426
- /* trivialTrailingClosure=*/ true );
2412
+ if (!AFT || IsImplicitlyCurriedInstanceMethod) {
2413
+ addMethodImpl ();
2414
+ } else {
2415
+ if (trivialTrailingClosure)
2416
+ addMethodImpl (/* includeDefaultArgs=*/ false ,
2417
+ /* trivialTrailingClosure=*/ true );
2418
+ if (hasInterestingDefaultValues (FD))
2419
+ addMethodImpl (/* includeDefaultArgs=*/ false );
2420
+ addMethodImpl (/* includeDefaultArgs=*/ true );
2427
2421
}
2428
- addMethodImpl ();
2429
2422
}
2430
2423
2431
2424
void addConstructorCall (const ConstructorDecl *CD, DeclVisibilityKind Reason,
0 commit comments