Skip to content

Commit d4f4dd3

Browse files
committed
fix cases where error message was not specific when missing an 'await' in autoclosure argument.
when the call in an autoclosure is async and throwing, if the call is covered by a try! or try?, the existing check that used Context::isAutoClosure was too pessimistic, saying it is not an autoclosure because errors are handled within it. For the error message about a missing await, we don't care about whether the throwing-ness was handled.
1 parent fa336cf commit d4f4dd3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,8 +1275,12 @@ class Context {
12751275
highlight = apply->getSourceRange();
12761276

12771277
auto diag = diag::async_call_without_await;
1278-
if (isAutoClosure())
1278+
// To produce a better error message, check if it is an autoclosure.
1279+
// We do not use 'Context::isAutoClosure' b/c it gives conservative answers.
1280+
if (Function && llvm::isa_and_nonnull<AutoClosureExpr>(
1281+
Function->getAbstractClosureExpr()))
12791282
diag = diag::async_call_without_await_in_autoclosure;
1283+
12801284
ctx.Diags.diagnose(node.getStartLoc(), diag)
12811285
.fixItInsert(node.getStartLoc(), "await ")
12821286
.highlight(highlight);

test/Concurrency/async_throwing.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,8 @@ func asyncTest() async {
105105
let _ = await invokeAuto(await try! throwingTask())
106106
let _ = await invokeAuto(await try? throwingTask())
107107

108-
// FIXME: we currently emit a less-helpful error message here.
109-
// it would be better if we said "call is 'async' in an autoclosure argument that is not marked with 'await'"
110-
let _ = await invokeAuto(try! throwingTask()) // expected-error{{call is 'async' but is not marked with 'await'}}
111-
let _ = await invokeAuto(try? throwingTask()) // expected-error{{call is 'async' but is not marked with 'await'}}
108+
let _ = await invokeAuto(try! throwingTask()) // expected-error{{call is 'async' in an autoclosure argument that is not marked with 'await'}}
109+
let _ = await invokeAuto(try? throwingTask()) // expected-error{{call is 'async' in an autoclosure argument that is not marked with 'await'}}
112110

113111
let _ = await invokeAuto(await try! throwingTask())
114112
let _ = await invokeAuto(await try? throwingTask())

0 commit comments

Comments
 (0)