Skip to content

Commit f234e53

Browse files
committed
Introduce and fix tests for @Sendable in nested positions
1 parent d8d648d commit f234e53

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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)