Skip to content

Commit a7586fb

Browse files
authored
Merge pull request #38774 from DougGregor/objc-import-block-without-prototype
2 parents 894b1ba + 38de7cc commit a7586fb

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

lib/ClangImporter/ImportName.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,7 +1316,7 @@ NameImporter::considerAsyncImport(
13161316
// void (^)()), we cannot importer it.
13171317
auto completionHandlerFunctionType =
13181318
completionHandlerParam->getType()->castAs<clang::BlockPointerType>()
1319-
->getPointeeType()->getAs<clang::FunctionProtoType>();
1319+
->getPointeeType()->getAs<clang::FunctionType>();
13201320
if (!completionHandlerFunctionType)
13211321
return notAsync("block parameter does not have a prototype");
13221322

@@ -1328,8 +1328,13 @@ NameImporter::considerAsyncImport(
13281328
// nullable NSError type, which would indicate that the async method could
13291329
// throw.
13301330
Optional<unsigned> completionHandlerErrorParamIndex;
1331-
auto completionHandlerParamTypes =
1332-
completionHandlerFunctionType->getParamTypes();
1331+
1332+
ArrayRef<clang::QualType> completionHandlerParamTypes;
1333+
if (auto prototype = completionHandlerFunctionType
1334+
->getAs<clang::FunctionProtoType>()) {
1335+
completionHandlerParamTypes = prototype->getParamTypes();
1336+
}
1337+
13331338
auto &clangCtx = clangDecl->getASTContext();
13341339
for (unsigned paramIdx : indices(completionHandlerParamTypes)) {
13351340
auto paramType = completionHandlerParamTypes[paramIdx];

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_res
2424
-(BOOL)findAnswerFailinglyWithError:(NSError * _Nullable * _Nullable)error completion:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswerFailingly(completionHandler:)")));
2525
-(void)findQAndAWithCompletionHandler:(void (^)(NSString *_Nullable_result, NSString *_Nullable answer, NSError * _Nullable))handler;
2626
-(void)findQuestionableAnswersWithCompletionHandler:(CompletionHandler)handler;
27-
-(void)doSomethingFun:(NSString *)operation then:(void (^)(void))completionHandler;
27+
-(void)doSomethingFun:(NSString *)operation then:(void (^)())completionHandler;
2828
-(void)getFortuneAsynchronouslyWithCompletionHandler:(void (^)(NSString *_Nullable, NSError * _Nullable))handler;
2929
-(void)getMagicNumberAsynchronouslyWithSeed:(NSInteger)seed completionHandler:(void (^)(NSInteger, NSError * _Nullable))handler;
3030
@property(readwrite) void (^completionHandler)(NSInteger);

0 commit comments

Comments
 (0)