|
12 | 12 | // MARK: Declarations // |
13 | 13 | //////////////////////// |
14 | 14 |
|
15 | | -class NonSendableKlass { |
| 15 | +class NonSendableKlass { // expected-complete-note 98{{}} |
16 | 16 | var field: NonSendableKlass? = nil |
17 | 17 | } |
18 | 18 |
|
@@ -823,223 +823,3 @@ actor ActorContainingSendableStruct { |
823 | 823 | } |
824 | 824 |
|
825 | 825 |
|
826 | | -//////////////////// |
827 | | -// MARK: Closures // |
828 | | -//////////////////// |
829 | | - |
830 | | -func closureTests() async { |
831 | | - func sendingClosure(_ x: sending () -> ()) { |
832 | | - } |
833 | | - |
834 | | - func testLetOneNSVariableError() async { |
835 | | - let x = NonSendableKlass() |
836 | | - sendingClosure { _ = x } // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
837 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
838 | | - sendingClosure { _ = x } // expected-note {{access can happen concurrently}} |
839 | | - } |
840 | | - |
841 | | - func testLetNonIsolatedUnsafeNSVariableNoError() async { |
842 | | - nonisolated(unsafe) let x = NonSendableKlass() |
843 | | - sendingClosure { _ = x } |
844 | | - sendingClosure { _ = x } |
845 | | - } |
846 | | - |
847 | | - func testLetOneNSVariableSVariableError() async { |
848 | | - let x = NonSendableKlass() |
849 | | - let y = CustomActorInstance() |
850 | | - sendingClosure { // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
851 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
852 | | - _ = x |
853 | | - _ = y |
854 | | - } |
855 | | - sendingClosure { // expected-note {{access can happen concurrently}} |
856 | | - _ = x |
857 | | - _ = y |
858 | | - } |
859 | | - } |
860 | | - |
861 | | - func testLetNonIsolatedUnsafeNSSVariableNoError() async { |
862 | | - nonisolated(unsafe) let x = NonSendableKlass() |
863 | | - let y = CustomActorInstance() |
864 | | - sendingClosure { |
865 | | - _ = x |
866 | | - _ = y |
867 | | - } |
868 | | - sendingClosure { |
869 | | - _ = x |
870 | | - _ = y |
871 | | - } |
872 | | - } |
873 | | - |
874 | | - func testLetTwoNSVariableError() async { |
875 | | - let x = NonSendableKlass() |
876 | | - let y = NonSendableKlass() |
877 | | - sendingClosure { // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
878 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
879 | | - _ = x |
880 | | - _ = y |
881 | | - } |
882 | | - sendingClosure { // expected-note {{access can happen concurrently}} |
883 | | - _ = x |
884 | | - _ = y |
885 | | - } |
886 | | - } |
887 | | - |
888 | | - func testLetTwoNSVariableError2() async { |
889 | | - nonisolated(unsafe) let x = NonSendableKlass() |
890 | | - let y = NonSendableKlass() |
891 | | - sendingClosure { // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
892 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
893 | | - _ = x |
894 | | - _ = y |
895 | | - } |
896 | | - sendingClosure { // expected-note {{access can happen concurrently}} |
897 | | - _ = x |
898 | | - _ = y |
899 | | - } |
900 | | - } |
901 | | - |
902 | | - func testLetTwoNSVariableError3() async { |
903 | | - nonisolated(unsafe) let x = NonSendableKlass() |
904 | | - nonisolated(unsafe) let y = NonSendableKlass() |
905 | | - sendingClosure { |
906 | | - _ = x |
907 | | - _ = y |
908 | | - } |
909 | | - sendingClosure { |
910 | | - _ = x |
911 | | - _ = y |
912 | | - } |
913 | | - } |
914 | | - |
915 | | - func testVarOneNSVariableError() async { |
916 | | - var x = NonSendableKlass() |
917 | | - x = NonSendableKlass() |
918 | | - |
919 | | - sendingClosure { _ = x } // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
920 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
921 | | - sendingClosure { _ = x } // expected-note {{access can happen concurrently}} |
922 | | - } |
923 | | - |
924 | | - func testVarNonIsolatedUnsafeNSVariableNoError() async { |
925 | | - nonisolated(unsafe) var x = NonSendableKlass() |
926 | | - x = NonSendableKlass() |
927 | | - |
928 | | - sendingClosure { _ = x } |
929 | | - sendingClosure { _ = x } |
930 | | - } |
931 | | - |
932 | | - func testVarOneNSVariableSVariableError() async { |
933 | | - var x = NonSendableKlass() |
934 | | - x = NonSendableKlass() |
935 | | - var y = CustomActorInstance() |
936 | | - y = CustomActorInstance() |
937 | | - sendingClosure { // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
938 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
939 | | - _ = x |
940 | | - _ = y |
941 | | - } |
942 | | - sendingClosure { // expected-note {{access can happen concurrently}} |
943 | | - _ = x |
944 | | - _ = y |
945 | | - } |
946 | | - } |
947 | | - |
948 | | - func testVarNonIsolatedUnsafeNSSVariableNoError() async { |
949 | | - nonisolated(unsafe) var x = NonSendableKlass() |
950 | | - x = NonSendableKlass() |
951 | | - var y = CustomActorInstance() |
952 | | - y = CustomActorInstance() |
953 | | - sendingClosure { |
954 | | - _ = x |
955 | | - _ = y |
956 | | - } |
957 | | - sendingClosure { |
958 | | - _ = x |
959 | | - _ = y |
960 | | - } |
961 | | - } |
962 | | - |
963 | | - func testVarTwoNSVariableError() async { |
964 | | - var x = NonSendableKlass() |
965 | | - x = NonSendableKlass() |
966 | | - var y = NonSendableKlass() |
967 | | - y = NonSendableKlass() |
968 | | - sendingClosure { // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
969 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
970 | | - _ = x |
971 | | - _ = y |
972 | | - } |
973 | | - sendingClosure { // expected-note {{access can happen concurrently}} |
974 | | - _ = x |
975 | | - _ = y |
976 | | - } |
977 | | - } |
978 | | - |
979 | | - func testVarTwoNSVariableError2() async { |
980 | | - nonisolated(unsafe) var x = NonSendableKlass() |
981 | | - x = NonSendableKlass() |
982 | | - var y = NonSendableKlass() |
983 | | - y = NonSendableKlass() |
984 | | - sendingClosure { // expected-warning {{sending value of non-Sendable type '() -> ()' risks causing data races}} |
985 | | - // expected-note @-1 {{Passing value of non-Sendable type '() -> ()' as a 'sending' argument to local function 'sendingClosure' risks causing races in between local and caller code}} |
986 | | - _ = x |
987 | | - _ = y |
988 | | - } |
989 | | - sendingClosure { // expected-note {{access can happen concurrently}} |
990 | | - _ = x |
991 | | - _ = y |
992 | | - } |
993 | | - } |
994 | | - |
995 | | - func testVarTwoNSVariableError3() async { |
996 | | - nonisolated(unsafe) var x = NonSendableKlass() |
997 | | - x = NonSendableKlass() |
998 | | - nonisolated(unsafe) var y = NonSendableKlass() |
999 | | - y = NonSendableKlass() |
1000 | | - sendingClosure { |
1001 | | - _ = x |
1002 | | - _ = y |
1003 | | - } |
1004 | | - sendingClosure { |
1005 | | - _ = x |
1006 | | - _ = y |
1007 | | - } |
1008 | | - } |
1009 | | - |
1010 | | - func testWithTaskDetached() async { |
1011 | | - let x1 = NonSendableKlass() |
1012 | | - Task.detached { _ = x1 } // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}} |
1013 | | - // expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}} |
1014 | | - Task.detached { _ = x1 } // expected-note {{access can happen concurrently}} |
1015 | | - |
1016 | | - nonisolated(unsafe) let x2 = NonSendableKlass() |
1017 | | - Task.detached { _ = x2 } |
1018 | | - Task.detached { _ = x2 } |
1019 | | - |
1020 | | - nonisolated(unsafe) let x3a = NonSendableKlass() |
1021 | | - nonisolated(unsafe) let x3b = NonSendableKlass() |
1022 | | - Task.detached { _ = x3a; _ = x3b } |
1023 | | - Task.detached { _ = x3a; _ = x3b } |
1024 | | - |
1025 | | - nonisolated(unsafe) let x4a = NonSendableKlass() |
1026 | | - let x4b = NonSendableKlass() |
1027 | | - Task.detached { _ = x4a; _ = x4b } // expected-warning {{sending value of non-Sendable type '() async -> ()' risks causing data races}} |
1028 | | - // expected-note @-1 {{Passing value of non-Sendable type '() async -> ()' as a 'sending' argument to static method 'detached(name:priority:operation:)' risks causing races in between local and caller code}} |
1029 | | - Task.detached { _ = x4a; _ = x4b } // expected-note {{access can happen concurrently}} |
1030 | | - } |
1031 | | - |
1032 | | - // The reason why this works is that we do not infer nonisolated(unsafe) |
1033 | | - // passed the begin_borrow [var_decl] of y. So we think the closure is |
1034 | | - // nonisolated(unsafe), but its uses via the begin_borrow [var_decl] is |
1035 | | - // not. |
1036 | | - func testNamedClosure() async { |
1037 | | - nonisolated(unsafe) let x = NonSendableKlass() |
1038 | | - let y = { |
1039 | | - _ = x |
1040 | | - } |
1041 | | - sendingClosure(y) // expected-warning {{sending 'y' risks causing data races}} |
1042 | | - // expected-note @-1 {{'y' used after being passed as a 'sending' parameter}} |
1043 | | - sendingClosure(y) // expected-note {{access can happen concurrently}} |
1044 | | - } |
1045 | | -} |
0 commit comments