Skip to content

Commit 9b99ed7

Browse files
authored
Merge pull request #61100 from DougGregor/subtype-sendable-funcs
2 parents 3bfbd5e + f234e53 commit 9b99ed7

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

lib/Sema/CSFix.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ getConcurrencyFixBehavior(
257257
switch (constraintKind) {
258258
case ConstraintKind::Conversion:
259259
case ConstraintKind::ArgumentConversion:
260+
case ConstraintKind::Subtype:
260261
break;
261262

262263
default:

test/Concurrency/preconcurrency_typealias.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,17 @@ func testAsync() async {
4646
}
4747
mutableVariable += 1
4848
}
49+
50+
// rdar://99518344 - @Sendable in nested positions
51+
@preconcurrency typealias OtherHandler = @Sendable () -> Void
52+
@preconcurrency typealias Handler = (@Sendable () -> OtherHandler?)?
53+
@preconcurrency func f(arg: Int, withFn: Handler?) {}
54+
55+
class C {
56+
func test() {
57+
f(arg: 5, withFn: { [weak self] () -> OtherHandler? in
58+
_ = self
59+
return nil
60+
})
61+
}
62+
}

test/attr/attr_concurrent.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
// REQUIRES: concurrency
33

44
// Concurrent attribute on a function type.
5+
// expected-note@+1{{found this candidate}}
56
func f(_ fn: @Sendable (Int) -> Int) { }
67

78
// Okay to overload @Sendable vs. not concurrent
9+
// expected-note@+1{{found this candidate}}
810
func f(_ fn: (Int) -> Int) { }
911

1012
// Concurrent attribute with other function attributes.
@@ -24,8 +26,10 @@ func passingConcurrentOrNot(
2426
_ cfn: @Sendable (Int) -> Int,
2527
ncfn: (Int) -> Int // expected-note{{parameter 'ncfn' is implicitly non-sendable}}{{9-9=@Sendable }}
2628
) {
29+
// Ambiguous because preconcurrency code doesn't consider `@Sendable`.
30+
f(cfn) // expected-error{{ambiguous use of 'f'}}
31+
2732
// Okay due to overloading
28-
f(cfn)
2933
f(ncfn)
3034

3135
acceptsConcurrent(cfn) // okay

0 commit comments

Comments
 (0)