Skip to content

[async type lowering] Handle Void return from @objc async methods. #34503

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/SIL/IR/AbstractionPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,17 @@ AbstractionPattern AbstractionPattern::getFunctionResultType() const {
callbackResultIndex = 1;
}
}

const clang::Type *clangResultType = nullptr;
if (callbackResultIndex < callbackParamTy->getNumParams()) {
clangResultType = callbackParamTy->getParamType(callbackResultIndex)
.getTypePtr();
} else {
clangResultType = getObjCMethod()->getASTContext().VoidTy.getTypePtr();
}

return AbstractionPattern(getGenericSignatureForFunctionComponent(),
getResultType(getType()),
callbackParamTy->getParamType(callbackResultIndex)
.getTypePtr());
getResultType(getType()), clangResultType);
}

return AbstractionPattern(getGenericSignatureForFunctionComponent(),
Expand Down
5 changes: 4 additions & 1 deletion test/SILGen/objc_async.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -I %S/Inputs/custom-modules -enable-experimental-concurrency %s -verify
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -I %S/Inputs/custom-modules -enable-experimental-concurrency %s -verify | %FileCheck %s
// REQUIRES: objc_interop

import Foundation
Expand All @@ -10,4 +10,7 @@ func testSlowServer(slowServer: SlowServer) async throws {
let _: Int = await slowServer.doSomethingSlow("mail")
// CHECK: objc_method {{.*}} $@convention(objc_method) (@convention(block) (Optional<NSString>, Optional<NSError>) -> (), SlowServer) -> ()
let _: String? = try await slowServer.findAnswer()

// CHECK: objc_method {{.*}} $@convention(objc_method) (NSString, @convention(block) () -> (), SlowServer) -> ()
await slowServer.serverRestart("somewhere")
}