Skip to content

Commit 82b44fc

Browse files
committed
[Concurrency] Fix async throws import nullability in the presence of typedefs.
1 parent 915afc3 commit 82b44fc

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,9 @@ namespace {
621621
// handler that can also express a thrown error.
622622
ImportTypeKind paramImportKind = ImportTypeKind::Parameter;
623623
unsigned paramIdx = param - type->param_type_begin();
624-
if (type == CompletionHandlerType &&
624+
if (CompletionHandlerType &&
625+
Impl.getClangASTContext().hasSameType(
626+
CompletionHandlerType, type) &&
625627
paramIdx != CompletionHandlerErrorParamIndex) {
626628
paramImportKind = ImportTypeKind::CompletionHandlerResultParameter;
627629
}
@@ -1585,6 +1587,8 @@ ImportedType ClangImporter::Implementation::importType(
15851587
if (auto blockPtrType = type->getAs<clang::BlockPointerType>()) {
15861588
completionHandlerType =
15871589
blockPtrType->getPointeeType()->castAs<clang::FunctionType>();
1590+
1591+
type = clang::QualType(blockPtrType, 0);
15881592
}
15891593
}
15901594

test/IDE/print_clang_objc_async.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
// CHECK-DAG: func findAnswerFailingly(completionHandler handler: @escaping (String?, Error?) -> Void) throws
2222
// CHECK-DAG: func findAnswerFailingly() async throws -> String
2323
// CHECK-DAG: func findQAndA() async throws -> (String?, String)
24+
// CHECK-DAG: func findQuestionableAnswers() async throws -> (String, String?)
2425
// CHECK-DAG: func doSomethingFun(_ operation: String) async
2526
// CHECK: {{^[}]$}}
2627

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
-(void)allOperationsWithCompletionHandler:(void (^)(NSArray<NSString *> *))completion;
99
@end
1010

11+
typedef void (^CompletionHandler)(NSString * _Nullable, NSString * _Nullable_result, NSError * _Nullable);
12+
1113
@interface SlowServer : NSObject <ServiceProvider>
1214
-(void)doSomethingSlow:(NSString *)operation completionHandler:(void (^)(NSInteger))handler;
1315
-(void)doSomethingDangerous:(NSString *)operation completionHandler:(void (^ _Nullable)(NSString *_Nullable, NSError * _Nullable))handler;
@@ -18,6 +20,7 @@
1820
-(void)findAnswerAsynchronously:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswer(completionHandler:)")));
1921
-(BOOL)findAnswerFailinglyWithError:(NSError * _Nullable * _Nullable)error completion:(void (^)(NSString *_Nullable, NSError * _Nullable))handler __attribute__((swift_name("findAnswerFailingly(completionHandler:)")));
2022
-(void)findQAndAWithCompletionHandler:(void (^)(NSString *_Nullable_result, NSString *_Nullable answer, NSError * _Nullable))handler;
23+
-(void)findQuestionableAnswersWithCompletionHandler:(CompletionHandler)handler;
2124
-(void)doSomethingFun:(NSString *)operation then:(void (^)(void))completionHandler;
2225
-(void)getFortuneAsynchronouslyWithCompletionHandler:(void (^)(NSString *_Nullable, NSError * _Nullable))handler;
2326
-(void)getMagicNumberAsynchronouslyWithSeed:(NSInteger)seed completionHandler:(void (^)(NSInteger, NSError * _Nullable))handler;

0 commit comments

Comments
 (0)