Skip to content

Commit ab4fa0a

Browse files
authored
Merge pull request #60119 from DougGregor/captured-var-preconcurrency
2 parents b1930a8 + c443b1a commit ab4fa0a

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2692,10 +2692,15 @@ namespace {
26922692
}
26932693

26942694
// Otherwise, we have concurrent access. Complain.
2695+
bool preconcurrencyContext =
2696+
getActorIsolationOfContext(
2697+
const_cast<DeclContext *>(getDeclContext())).preconcurrency();
2698+
26952699
ctx.Diags.diagnose(
26962700
loc, diag::concurrent_access_of_local_capture,
26972701
parent.dyn_cast<LoadExpr *>(),
2698-
var->getDescriptiveKind(), var->getName());
2702+
var->getDescriptiveKind(), var->getName())
2703+
.warnUntilSwiftVersionIf(preconcurrencyContext, 6);
26992704
return true;
27002705
}
27012706

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func testSendable(fn: () -> Void) {
114114
func testSendableInAsync() async {
115115
var x = 17
116116
doSomethingConcurrentlyButUnsafe {
117-
x = 42 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
117+
x = 42 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
118118
}
119119
print(x)
120120
}

test/Concurrency/concurrent_value_checking.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ func testConcurrency() {
174174
func testUnsafeSendableNothing() {
175175
var x = 5
176176
acceptUnsafeSendable {
177-
x = 17 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
177+
x = 17 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
178178
}
179179
print(x)
180180
}
181181

182182
func testUnsafeSendableInAsync() async {
183183
var x = 5
184184
acceptUnsafeSendable {
185-
x = 17 // expected-error{{mutation of captured var 'x' in concurrently-executing code}}
185+
x = 17 // expected-warning{{mutation of captured var 'x' in concurrently-executing code}}
186186
}
187187
print(x)
188188
}

0 commit comments

Comments
 (0)