@@ -22,9 +22,57 @@ protocol ProtocolWithMixedReqs {
22
22
func nonSendingParamAndSendingResult( _ x: NonSendableKlass ) -> sending NonSendableKlass // expected-note 4{{}}
23
23
}
24
24
25
- /////////////////
26
- // MARK: Tests //
27
- /////////////////
25
+ /////////////////////////////////
26
+ // MARK: Normal Function Tests //
27
+ /////////////////////////////////
28
+
29
+ func functionWithSendingResult( ) -> sending NonSendableKlass { fatalError ( ) }
30
+ func functionWithoutSendingResult( ) -> NonSendableKlass { fatalError ( ) }
31
+ func functionWithSendingParameter( _ x: sending NonSendableKlass) { fatalError ( ) }
32
+ func functionWithoutSendingParameter( _ x: NonSendableKlass ) { fatalError ( ) }
33
+
34
+ func takeFnWithSendingResult( _ fn: ( ) -> sending NonSendableKlass) { }
35
+ func takeFnWithoutSendingResult( _ fn: ( ) -> NonSendableKlass ) { }
36
+ func takeFnWithSendingParam( _ fn: ( sending NonSendableKlass) -> ( ) ) { }
37
+ func takeFnWithoutSendingParam( _ fn: ( NonSendableKlass ) -> ( ) ) { }
38
+
39
+ func testFunctionMatching( ) {
40
+ let _: ( NonSendableKlass ) -> ( ) = functionWithSendingParameter
41
+ // expected-error @-1 {{cannot convert value of type '@Sendable (sending NonSendableKlass) -> ()' to specified type '(NonSendableKlass) -> ()'}}
42
+ let _: ( sending NonSendableKlass) -> ( ) = functionWithSendingParameter
43
+
44
+ let _: ( NonSendableKlass ) -> ( ) = functionWithoutSendingParameter
45
+ let _: ( sending NonSendableKlass) -> ( ) = functionWithoutSendingParameter
46
+
47
+ takeFnWithSendingParam ( functionWithSendingParameter)
48
+ takeFnWithoutSendingParam ( functionWithSendingParameter)
49
+ // expected-error @-1 {{@Sendable (sending NonSendableKlass) -> ()' to expected argument type '(NonSendableKlass) -> ()}}
50
+ takeFnWithSendingParam ( functionWithoutSendingParameter)
51
+ takeFnWithoutSendingParam ( functionWithoutSendingParameter)
52
+ }
53
+
54
+ func testReturnValueMatching( ) {
55
+ let _: ( ) -> NonSendableKlass = functionWithSendingResult
56
+ let _: ( ) -> sending NonSendableKlass = functionWithSendingResult
57
+ let _: ( ) -> NonSendableKlass = functionWithoutSendingResult
58
+ let _: ( ) -> sending NonSendableKlass = functionWithoutSendingResult
59
+ // expected-error @-1 {{cannot convert value of type '@Sendable () -> NonSendableKlass' to specified type '() -> sending NonSendableKlass'}}
60
+
61
+ takeFnWithSendingResult ( functionWithSendingResult)
62
+ takeFnWithSendingResult ( functionWithoutSendingResult)
63
+ // expected-error @-1 {{cannot convert value of type '@Sendable () -> NonSendableKlass' to expected argument type '() -> sending NonSendableKlass'}}
64
+ let x : ( ) -> NonSendableKlass = { fatalError ( ) }
65
+ takeFnWithSendingResult ( x)
66
+ // expected-error @-1 {{cannot convert value of type '() -> NonSendableKlass' to expected argument type '() -> sending NonSendableKlass'}}
67
+
68
+ takeFnWithoutSendingResult ( functionWithSendingResult)
69
+ takeFnWithoutSendingResult ( functionWithoutSendingResult)
70
+ takeFnWithoutSendingResult ( x)
71
+ }
72
+
73
+ //////////////////////////
74
+ // MARK: Protocol Tests //
75
+ //////////////////////////
28
76
29
77
struct MatchSuccess : ProtocolWithSendingReqs , ProtocolWithMixedReqs {
30
78
func sendingResult( ) -> sending NonSendableKlass { fatalError ( ) }
0 commit comments