Skip to content

Commit 4394757

Browse files
committed
Downgrade "reference to captured var" to warn in preconcurrency code.
Fixes rdar://97228088.
1 parent 3a67c1a commit 4394757

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
@@ -2632,10 +2632,15 @@ namespace {
26322632
}
26332633

26342634
// Otherwise, we have concurrent access. Complain.
2635+
bool preconcurrencyContext =
2636+
getActorIsolationOfContext(
2637+
const_cast<DeclContext *>(getDeclContext())).preconcurrency();
2638+
26352639
ctx.Diags.diagnose(
26362640
loc, diag::concurrent_access_of_local_capture,
26372641
parent.dyn_cast<LoadExpr *>(),
2638-
var->getDescriptiveKind(), var->getName());
2642+
var->getDescriptiveKind(), var->getName())
2643+
.warnUntilSwiftVersionIf(preconcurrencyContext, 6);
26392644
return true;
26402645
}
26412646

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)