Skip to content

Commit 9c48c9e

Browse files
committed
[Sema]: don't warn about optional Void async-lets either
1 parent 2e901a1 commit 9c48c9e

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,12 +1232,9 @@ Pattern *TypeChecker::coercePatternToType(
12321232
} else if (diagTy->isEqual(Context.TheEmptyTupleType)) {
12331233
// Async-let bindings are commonly used to run a Void-returning
12341234
// synchronous function in an async context. As a policy choice, don't
1235-
// diagnose a Void result on these bindings as potentially unexpected.
1236-
if (!isOptional && var->isAsyncLet()) {
1237-
shouldRequireType = false;
1238-
} else {
1239-
shouldRequireType = true;
1240-
}
1235+
// diagnose an inferred Void type (or optional thereof) on such bindings
1236+
// as potentially unexpected.
1237+
shouldRequireType = var->isAsyncLet() ? false : true;
12411238
} else if (auto MTT = diagTy->getAs<AnyMetatypeType>()) {
12421239
if (MTT->getInstanceType()->isAnyObject())
12431240
shouldRequireType = true;

test/decl/var/async_let.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,16 @@ func testVoidResultTypeDiagnostics() async {
6363
async let void6 = asyncVoid()
6464
await void6
6565

66-
// expected-warning @+2 {{constant 'maybeVoid' inferred to have type '()?', which may be unexpected}}
67-
// expected-note @+1 {{add an explicit type annotation to silence this warning}}
6866
async let maybeVoid = { Bool.random() ? () : nil }()
6967
await maybeVoid
7068

69+
do {
70+
final class C: Sendable { func doit() {} }
71+
let c: C? = nil
72+
async let maybeVoid2 = c?.doit()
73+
let _: ()? = await maybeVoid2
74+
}
75+
7176
// expected-warning @+2 {{constant 'boxOVoid' inferred to have type '[()]', which may be unexpected}}
7277
// expected-note @+1 {{add an explicit type annotation to silence this warning}}
7378
async let boxOVoid = { [(), (), ()] }()

0 commit comments

Comments
 (0)