Skip to content

Commit 84f4cc0

Browse files
committed
[Concurrency] Finish and add tests for ban on async with @objc.
1 parent 3cfe390 commit 84f4cc0

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,6 +4369,8 @@ NOTE(not_objc_generic_type_param,none,
43694369
NOTE(not_objc_function_type_param,none,
43704370
"function types cannot be represented in Objective-C unless their "
43714371
"parameters and returns can be", ())
4372+
ERROR(not_objc_function_async,none,
4373+
"'async' function cannot be represented in Objective-C", ())
43724374
NOTE(not_objc_function_type_async,none,
43734375
"'async' function types cannot be represented in Objective-C", ())
43744376
NOTE(not_objc_function_type_throwing,none,

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,16 @@ bool swift::isRepresentableInObjC(
613613
}
614614
}
615615

616+
// Async functions cannot be mapped into Objective-C.
617+
if (AFD->hasAsync()) {
618+
if (Diagnose) {
619+
AFD->diagnose(diag::not_objc_function_async)
620+
.highlight(AFD->getAsyncLoc());
621+
describeObjCReason(AFD, Reason);
622+
}
623+
return false;
624+
}
625+
616626
// Throwing functions must map to a particular error convention.
617627
if (AFD->hasThrows()) {
618628
DeclContext *dc = const_cast<AbstractFunctionDecl *>(AFD);

test/attr/attr_objc.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %s -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference
2-
// RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %s -function-definitions=true -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference | %FileCheck %s
3-
// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %s -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference > %t.ast
1+
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -verify-ignore-unknown %s -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference -enable-experimental-concurrency
2+
// RUN: %target-swift-ide-test -skip-deinit=false -print-ast-typechecked -source-filename %s -function-definitions=true -prefer-type-repr=false -print-implicit-attrs=true -explode-pattern-binding-decls=true -disable-objc-attr-requires-foundation-module -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference -enable-experimental-concurrency | %FileCheck %s
3+
// RUN: not %target-swift-frontend -typecheck -dump-ast -disable-objc-attr-requires-foundation-module %s -swift-version 4 -enable-source-import -I %S/Inputs -enable-swift3-objc-inference -enable-experimental-concurrency > %t.ast
44
// RUN: %FileCheck -check-prefix CHECK-DUMP %s < %t.ast
55
// REQUIRES: objc_interop
66

@@ -2381,3 +2381,11 @@ class SR12801 {
23812381
@objc subscript<T>(foo : [T]) -> Int { return 0 }
23822382
// expected-error@-1 {{subscript cannot be marked @objc because it has generic parameters}}
23832383
}
2384+
2385+
// async cannot be compiled with @objc.
2386+
class Concurrency {
2387+
@objc func doBigJob() async -> Int { return 0 } // expected-error{{'async' function cannot be represented in Objective-C}}
2388+
2389+
@objc func takeAnAsync(_ fn: () async -> Int) { } // expected-error{{method cannot be marked @objc because the type of the parameter cannot be represented in Objective-C}}
2390+
// expected-note@-1{{'async' function types cannot be represented in Objective-C}}
2391+
}

tools/swift-ide-test/swift-ide-test.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ static llvm::cl::opt<std::string>
756756
ExplicitSwiftModuleMap("explicit-swift-module-map-file",
757757
llvm::cl::desc("JSON file to include explicit Swift modules"),
758758
llvm::cl::cat(Category));
759+
760+
static llvm::cl::opt<bool>
761+
EnableExperimentalConcurrency("enable-experimental-concurrency",
762+
llvm::cl::desc("Enable experimental concurrency model"),
763+
llvm::cl::init(false));
764+
759765
} // namespace options
760766

761767
static std::unique_ptr<llvm::MemoryBuffer>
@@ -3820,6 +3826,9 @@ int main(int argc, char *argv[]) {
38203826
if (options::EnableCxxInterop) {
38213827
InitInvok.getLangOptions().EnableCXXInterop = true;
38223828
}
3829+
if (options::EnableExperimentalConcurrency) {
3830+
InitInvok.getLangOptions().EnableExperimentalConcurrency = true;
3831+
}
38233832

38243833
// We disable source location resolutions from .swiftsourceinfo files by
38253834
// default to match sourcekitd-test's and ide clients' expected behavior

0 commit comments

Comments
 (0)