Skip to content

Commit dd7ce80

Browse files
committed
[Concurrency] Reject top-level asynchronous code for now.
We haven't implemented any support for top-level async code yet, so reject it in effects checking rather than crashing in the SIL verifier. Fixes rdar://71512818.
1 parent 413352b commit dd7ce80

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,9 @@ class Context {
985985
}
986986

987987
static Context forTopLevelCode(TopLevelCodeDecl *D) {
988-
// Top-level code implicitly handles errors and 'async' calls.
989-
return Context(/*handlesErrors=*/true, /*handlesAsync=*/true, None);
988+
// Top-level code implicitly handles errors.
989+
// TODO: Eventually, it will handle async as well.
990+
return Context(/*handlesErrors=*/true, /*handlesAsync=*/false, None);
990991
}
991992

992993
static Context forFunction(AbstractFunctionDecl *D) {

test/decl/var/async_let.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
// REQUIRES: concurrency
44

5-
async let x = 1 // okay
5+
func test() async {
6+
async let x = 1 // okay
7+
_ = await x
8+
}
69

710
struct X {
811
async let x = 1 // expected-error{{'async let' can only be used on local declarations}}

test/stmt/async.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
3+
// REQUIRES: concurrency
4+
5+
func f() async -> Int { 0 }
6+
7+
_ = await f() // expected-error{{'async' in a function that does not support concurrency}}
8+
9+
async let y = await f() // expected-error{{'async let' in a function that does not support concurrency}}
10+
// expected-error@-1{{'async' in a function that does not support concurrency}}

0 commit comments

Comments
 (0)