Skip to content

Commit eda621f

Browse files
committed
[Concurrency] Only suggest adding 'async' to functions.
1 parent a535463 commit eda621f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,9 +2156,10 @@ static Type validateParameterType(ParamDecl *decl) {
21562156
if (fnType->isAsync() &&
21572157
!(isa<AbstractFunctionDecl>(dc) &&
21582158
cast<AbstractFunctionDecl>(dc)->hasAsync())) {
2159-
auto func = cast<AbstractFunctionDecl>(dc);
21602159
decl->diagnose(diag::async_autoclosure_nonasync_function);
2161-
func->diagnose(diag::note_add_async_to_function, func->getName());
2160+
if (auto func = dyn_cast<FuncDecl>(dc)) {
2161+
func->diagnose(diag::note_add_async_to_function, func->getName());
2162+
}
21622163
}
21632164
}
21642165
}

test/expr/unary/async_await.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ func acceptAutoclosureNonAsyncBad(_: @autoclosure () async -> Int) { }
4040
// expected-error@-1{{'async' autoclosure parameter in a non-'async' function}}
4141
// expected-note@-2{{add 'async' to function 'acceptAutoclosureNonAsyncBad' to make it asynchronous}}
4242

43+
struct HasAsyncBad {
44+
init(_: @autoclosure () async -> Int) { }
45+
// expected-error@-1{{'async' autoclosure parameter in a non-'async' function}}
46+
}
47+
4348
func testAutoclosure() async {
4449
__await acceptAutoclosureAsync(getInt()) // expected-error{{call is 'async' in an autoclosure argument is not marked with 'await'}}
4550
__await acceptAutoclosureNonAsync(getInt()) // expected-error{{'async' in an autoclosure that does not support concurrency}}

0 commit comments

Comments
 (0)