Skip to content

Commit 67d465f

Browse files
Enable warnings about never mutated weak var.
1 parent 791ab3b commit 67d465f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4000,7 +4000,7 @@ VarDeclUsageChecker::~VarDeclUsageChecker() {
40004000

40014001
// If this variable has WeakStorageType, then it can be mutated in ways we
40024002
// don't know.
4003-
if (var->getInterfaceType()->is<WeakStorageType>())
4003+
if (var->getInterfaceType()->is<WeakStorageType>() && !DC->getASTContext().LangOpts.hasFeature(Feature::WeakLet))
40044004
access |= RK_Written;
40054005

40064006
// Diagnose variables that were never used (other than their

test/Concurrency/weak_ref_sendability.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ final class CheckSendability12: Sendable {
110110

111111

112112
func checkWeakCapture1(_ strongRef: S) -> @Sendable () -> Void {
113+
// expected-new-warning@+1 {{variable 'weakRef' was never mutated; consider changing to 'let' constant}}
113114
weak var weakRef: S? = strongRef
114115
return {
115116
// expected-old-error@+2 {{reference to captured var 'weakRef' in concurrently-executing code}}
@@ -137,7 +138,7 @@ func checkWeakCapture3(_ strongRef: S) -> @Sendable () -> Void {
137138
}
138139

139140
func checkWeakCapture4(_ strongRef: NS) -> @Sendable () -> Void {
140-
// TODO: warning consider changing to 'let' constant
141+
// expected-new-warning@+1 {{variable 'weakRef' was never mutated; consider changing to 'let' constant}}
141142
weak var weakRef: NS? = strongRef
142143
return {
143144
// expected-old-error@+4 {{capture of 'weakRef' with non-sendable type 'NS?' in a '@Sendable' closure}}

0 commit comments

Comments
 (0)