Skip to content

Commit 0579b35

Browse files
committed
[send-non-sendable] Add complete- warnings to sendnonsendable_basic.swift.
So we can validate that we are not missing any diagnostics.
1 parent 82fbde0 commit 0579b35

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

test/Concurrency/sendnonsendable_basic.swift

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-frontend -emit-sil -strict-concurrency=complete -enable-experimental-feature SendNonSendable -disable-availability-checking -verify %s -o /dev/null
1+
// RUN: %target-swift-frontend -emit-sil -strict-concurrency=complete -disable-availability-checking -verify -verify-additional-prefix complete- %s -o /dev/null
2+
// RUN: %target-swift-frontend -emit-sil -strict-concurrency=complete -enable-experimental-feature SendNonSendable -disable-availability-checking -verify -verify-additional-prefix sns- %s -o /dev/null
23

34
// REQUIRES: concurrency
45
// REQUIRES: asserts
@@ -8,7 +9,7 @@
89
////////////////////////
910

1011
/// Classes are always non-sendable, so this is non-sendable
11-
class NonSendableKlass {
12+
class NonSendableKlass { // expected-complete-note 9{{}}
1213
func asyncCall() async {}
1314
}
1415

@@ -33,20 +34,19 @@ func useValue<T>(_ x: T) {}
3334

3435
extension Actor {
3536
func noWarningIfCallingGetter() async {
36-
// We do not emit a warning in this case since we are calling transferring
37-
// the result of a getter of an actor. The result of this getter could not
38-
// have been returned from the actor without us emitting a warning as shown
39-
// by the test klassGetter below.
37+
// We should emit an error here since self is an actor which is non
38+
// sendable, so we could be accessing isolated information from a part of
39+
// the actor.
4040
await self.klass.asyncCall()
41+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass' outside of actor-isolated context may introduce data races}}
4142
}
4243

4344
func warningIfCallingAsyncOnFinalField() async {
4445
// Since we are calling finalKlass directly, we emit a warning here.
4546
await self.finalKlass.asyncCall() // expected-warning {{}}
4647
}
4748

48-
// We warn on this since we are escaping an actor field out of its isolation
49-
// domain.
49+
// We do not warn on this since we warn in the caller of our getter instead.
5050
var klassGetter: NonSendableKlass {
5151
self.finalKlass
5252
}
@@ -82,10 +82,13 @@ func closureInOut(_ a: Actor) async {
8282
var closure = {}
8383
closure = { useInOut(&contents) }
8484

85-
await a.useKlass(ns0) // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
86-
await a.useKlass(ns1) // expected-note {{access here could race}}
85+
await a.useKlass(ns0)
86+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
87+
// expected-sns-warning @-2 {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
88+
await a.useKlass(ns1) // expected-sns-note {{access here could race}}
89+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
8790

88-
closure() // expected-note {{access here could race}}
91+
closure() // expected-sns-note {{access here could race}}
8992
}
9093

9194
func closureInOut2(_ a: Actor) async {
@@ -98,11 +101,13 @@ func closureInOut2(_ a: Actor) async {
98101

99102
var closure = {}
100103

101-
await a.useKlass(ns0) // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
104+
await a.useKlass(ns0) // expected-sns-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
105+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
102106

103-
closure = { useInOut(&contents) } // expected-note {{access here could race}}
107+
closure = { useInOut(&contents) } // expected-sns-note {{access here could race}}
104108

105-
await a.useKlass(ns1) // expected-note {{access here could race}}
109+
await a.useKlass(ns1) // expected-sns-note {{access here could race}}
110+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
106111

107112
closure()
108113
}
@@ -118,11 +123,13 @@ func closureNonInOut(_ a: Actor) async {
118123
var closure = {}
119124

120125
await a.useKlass(ns0)
126+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
121127

122128
closure = { useValue(contents) }
123129

124-
await a.useKlass(ns1) // expected-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
130+
await a.useKlass(ns1) // expected-sns-warning {{passing argument of non-sendable type 'NonSendableKlass' from nonisolated context to actor-isolated context at this call site could yield a race with accesses later in this function}}
131+
// expected-complete-warning @-1 {{passing argument of non-sendable type 'NonSendableKlass'}}
125132

126-
closure() // expected-note {{access here could race}}
133+
closure() // expected-sns-note {{access here could race}}
127134
}
128135

0 commit comments

Comments
 (0)