You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/Concurrency/transfernonsendable_region_based_sendability.swift
+23-13Lines changed: 23 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -667,8 +667,8 @@ func test_tuple_formation(a : A, i : Int) async {
667
667
foo_noniso(ns012);
668
668
foo_noniso(ns13);
669
669
case4:
670
-
await a.foo(ns012) // expected-tns-warning {{sending value of non-Sendable type '(NonSendable, NonSendable, NonSendable)' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
671
-
// TODO: Interestingly with complete, we emit this error 3 times?!
670
+
await a.foo(ns012) // expected-tns-warning {{sending value of non-Sendable type '(NonSendable, NonSendable, NonSendable)' risks causing data races}}
671
+
// expected-tns-note @-1 {{sending value of non-Sendable type '(NonSendable, NonSendable, NonSendable)' to actor-isolated instance method 'foo' risks causing data races between actor-isolated and local nonisolated uses}}
672
672
// expected-complete-warning @-2 3{{passing argument of non-sendable type '(NonSendable, NonSendable, NonSendable)' into actor-isolated context may introduce data races}}
673
673
674
674
if bool {
@@ -687,7 +687,8 @@ func test_tuple_formation(a : A, i : Int) async {
687
687
foo_noniso(ns13); // expected-tns-note {{access can happen concurrently}}
688
688
}
689
689
default:
690
-
await a.foo(ns13) // expected-tns-warning {{sending value of non-Sendable type '(NonSendable, NonSendable)' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
690
+
await a.foo(ns13) // expected-tns-warning {{sending value of non-Sendable type '(NonSendable, NonSendable)' risks causing data races}}
691
+
// expected-tns-note @-1 {{sending value of non-Sendable type '(NonSendable, NonSendable)' to actor-isolated instance method 'foo' risks causing data races between actor-isolated and local nonisolated uses}}
691
692
// expected-complete-warning @-1 2{{passing argument of non-sendable type '(NonSendable, NonSendable)' into actor-isolated context may introduce data races}}
692
693
693
694
if bool {
@@ -823,9 +824,10 @@ func one_consume_many_require_varag(a : A) async {
823
824
letns3=NonSendable();
824
825
letns4=NonSendable();
825
826
826
-
//TODO: find a way to make the type used in the diagnostic more specific than the signature type
827
+
//TODO: find a way to make the type used in the diagnostic more specific than the signature type
827
828
await a.foo_vararg(ns0, ns1, ns2);
828
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
829
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
830
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
829
831
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
830
832
831
833
if bool {
@@ -843,7 +845,8 @@ func one_consume_one_require_vararg(a : A) async {
843
845
letns2=NonSendable();
844
846
845
847
await a.foo_vararg(ns0, ns1, ns2);
846
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
848
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
849
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
847
850
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
848
851
849
852
foo_noniso_vararg(ns0, ns1, ns2); // expected-tns-note 1{{access can happen concurrently}}
@@ -858,13 +861,16 @@ func many_consume_one_require_vararg(a : A) async {
858
861
letns5=NonSendable();
859
862
860
863
await a.foo_vararg(ns0, ns3, ns3)
861
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
864
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
865
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
862
866
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
863
867
await a.foo_vararg(ns4, ns1, ns4)
864
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
868
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
869
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
865
870
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
866
871
await a.foo_vararg(ns5, ns5, ns2)
867
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
872
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
873
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
868
874
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
869
875
870
876
foo_noniso_vararg(ns0, ns1, ns2); // expected-tns-note 3{{access can happen concurrently}}
@@ -881,13 +887,16 @@ func many_consume_many_require_vararg(a : A) async {
881
887
letns7=NonSendable();
882
888
883
889
await a.foo_vararg(ns0, ns3, ns3)
884
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
890
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
891
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
885
892
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
886
893
await a.foo_vararg(ns4, ns1, ns4)
887
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
894
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
895
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
888
896
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
889
897
await a.foo_vararg(ns5, ns5, ns2)
890
-
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
898
+
// expected-tns-warning @-1 {{sending value of non-Sendable type 'Any...' risks causing data races}}
899
+
// expected-tns-note @-2 {{sending value of non-Sendable type 'Any...' to actor-isolated instance method 'foo_vararg' risks causing data races between actor-isolated and local nonisolated uses}}
891
900
// expected-complete-warning @-2 {{passing argument of non-sendable type 'Any...' into actor-isolated context may introduce data races}}
892
901
893
902
if bool {
@@ -925,7 +934,8 @@ func enum_test(a : A) async {
925
934
case.E2:
926
935
switch(e3){
927
936
caselet.E3(ns3):
928
-
await a.foo(ns3.x); // expected-tns-warning {{sending value of non-Sendable type 'Any' with later accesses from nonisolated context to actor-isolated context risks causing data races}}
937
+
await a.foo(ns3.x) // expected-tns-warning {{sending value of non-Sendable type 'Any' risks causing data races}}
938
+
// expected-tns-note @-1 {{sending value of non-Sendable type 'Any' to actor-isolated instance method 'foo' risks causing data races between actor-isolated and local nonisolated uses}}
929
939
// expected-complete-warning @-1 {{passing argument of non-sendable type 'Any' into actor-isolated context may introduce data races}}
// READ THIS: This test is only intended to test typed errors that are fallback
7
+
// error paths that are only invoked if we can't find a name for the value being
8
+
// sent. Since in most cases we are able to infer a name, we do not invoke these
9
+
// very often (and in truth in normal compilation we would like to never emit
10
+
// them). To make sure that we can at least test them out, this test uses an
11
+
// asserts only option that causes us to emit typed errors even when we find a
12
+
// name.
13
+
14
+
////////////////////////
15
+
// MARK: Declarations //
16
+
////////////////////////
17
+
18
+
classNonSendableKlass{}
19
+
20
+
@MainActorfunc transferToMain<T>(_ t:T)async{}
21
+
22
+
/////////////////
23
+
// MARK: Tests //
24
+
/////////////////
25
+
26
+
func simpleUseAfterFree()async{
27
+
letx=NonSendableKlass()
28
+
awaittransferToMain(x) // expected-error {{sending value of non-Sendable type 'NonSendableKlass' risks causing data races}}
29
+
// expected-note @-1 {{sending value of non-Sendable type 'NonSendableKlass' to main actor-isolated global function 'transferToMain' risks causing data races between main actor-isolated and local nonisolated uses}}
30
+
print(x) // expected-note {{access can happen concurrently}}
0 commit comments