File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed
Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 = { [ ( ) , ( ) , ( ) ] } ( )
You can’t perform that action at this time.
0 commit comments