File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -2584,7 +2584,8 @@ bool TypeVarBindingProducer::computeNext() {
2584
2584
//
2585
2585
// Let's not perform $T? -> $T for closure result types to avoid having
2586
2586
// to re-discover solutions that differ only in location of optional
2587
- // injection.
2587
+ // injection. `Void` is a special case because in $T_result position
2588
+ // it has special semantics and enables T? -> Void conversions.
2588
2589
//
2589
2590
// The pattern with such type variables is:
2590
2591
//
@@ -2595,7 +2596,7 @@ bool TypeVarBindingProducer::computeNext() {
2595
2596
// expression is non-optional), if we allow both the solver would
2596
2597
// find two solutions that differ only in location of optional
2597
2598
// injection.
2598
- if (!TypeVar->getImpl ().isClosureResultType ()) {
2599
+ if (!TypeVar->getImpl ().isClosureResultType () || objTy-> isVoid () ) {
2599
2600
// If T is a type variable, only attempt this if both the
2600
2601
// type variable we are trying bindings for, and the type
2601
2602
// variable we will attempt to bind, both have the same
Original file line number Diff line number Diff line change @@ -1283,3 +1283,25 @@ do {
1283
1283
}
1284
1284
}
1285
1285
}
1286
+
1287
+ // Make sure that closure gets both Void? and Void attempted
1288
+ // otherwise it won't be possible to type-check the second closure.
1289
+ do {
1290
+ struct Semaphore {
1291
+ func signal( ) -> Int { }
1292
+ }
1293
+
1294
+ func compute( _ completion: ( Semaphore ? ) -> Void ? ) { }
1295
+
1296
+ func test( ) {
1297
+ compute { $0? . signal ( ) }
1298
+ // expected-warning@-1 {{result of call to 'signal()' is unused}}
1299
+
1300
+ true
1301
+ ? compute ( { $0? . signal ( ) } ) // expected-warning {{result of call to 'signal()' is unused}}
1302
+ : compute ( {
1303
+ let sem = $0!
1304
+ sem. signal ( ) // expected-warning {{result of call to 'signal()' is unused}}
1305
+ } )
1306
+ }
1307
+ }
You can’t perform that action at this time.
0 commit comments