Skip to content

Commit 642392c

Browse files
committed
Computed properties can't be async, don't even try
The fix-it was being a little too eager to label function decls async. Computed properties, or AccessorDecls are function declarations, but they don't have parentheses, so trying to add `async` to them causes crashing. Furthermore, they can't be async at all, so suggesting that we make them async is just wrong. We shouldn't give folks a glimmer of hope where there is none to be had.
1 parent 29cfd3e commit 642392c

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ static bool checkAsyncHandler(FuncDecl *func, bool diagnose) {
133133

134134
void swift::addAsyncNotes(AbstractFunctionDecl const* func) {
135135
assert(func);
136-
if (!isa<DestructorDecl>(func)) {
136+
if (!isa<DestructorDecl>(func) && !isa<AccessorDecl>(func)) {
137137
auto note =
138138
func->diagnose(diag::note_add_async_to_function, func->getName());
139139

@@ -143,8 +143,7 @@ void swift::addAsyncNotes(AbstractFunctionDecl const* func) {
143143
: "async throws";
144144

145145
note.fixItReplace(SourceRange(func->getThrowsLoc()), replacement);
146-
147-
} else {
146+
} else if (func->getParameters()->getRParenLoc().isValid()) {
148147
note.fixItInsert(func->getParameters()->getRParenLoc().getAdvancedLoc(1),
149148
" async");
150149
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2+
// REQUIRES: concurrency
3+
4+
func asyncFunc(_ value: String) async {}
5+
6+
class ComputedPropertyClass {
7+
var meep: String {
8+
//expected-error@+1:11{{'async' call in a function that does not support concurrency}}
9+
await asyncFunc("Meep")
10+
return "15"
11+
}
12+
}

0 commit comments

Comments
 (0)