Skip to content

Commit c5b7208

Browse files
authored
Merge pull request swiftlang#36718 from DougGregor/limit-global-var-diagnose
Only diagnose references to globals under -warn-concurrency.
2 parents 63d0b73 + f8cb209 commit c5b7208

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ namespace {
14601460
///
14611461
/// \returns true if we diagnosed the entity, \c false otherwise.
14621462
bool diagnoseReferenceToUnsafeGlobal(ValueDecl *value, SourceLoc loc) {
1463-
if (!shouldDiagnoseExistingDataRaces(getDeclContext()))
1463+
if (!ctx.LangOpts.WarnConcurrency)
14641464
return false;
14651465

14661466
// Only diagnose direct references to mutable global state.

test/decl/var/effectful_properties_global.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ var intAsyncProp : Int {
55
get async { 0 }
66
}
77

8-
var intThrowsProp : Int { // expected-note 2 {{var declared here}}
8+
var intThrowsProp : Int {
99
get throws { 0 }
1010
}
1111

1212
var asyncThrowsProp : Int {
13-
// expected-warning@+1 {{reference to var 'intThrowsProp' is not concurrency-safe because it involves shared mutable state}}
1413
get async throws { try await intAsyncProp + intThrowsProp }
1514
}
1615

1716
func hello() async {
18-
// expected-warning@+1 {{reference to var 'intThrowsProp' is not concurrency-safe because it involves shared mutable state}}
1917
_ = intThrowsProp // expected-error{{property access can throw, but it is not marked with 'try' and the error is not handled}}
2018

2119
_ = intAsyncProp // expected-error{{property access is 'async' but is not marked with 'await'}}
@@ -25,7 +23,7 @@ class C {
2523
var counter : Int = 0
2624
}
2725

28-
var refTypeThrowsProp : C { // expected-note {{var declared here}}
26+
var refTypeThrowsProp : C {
2927
get throws { return C() }
3028
}
3129

@@ -34,9 +32,8 @@ var refTypeAsyncProp : C {
3432
}
3533

3634
func salam() async {
37-
// expected-warning@+1 {{reference to var 'refTypeThrowsProp' is not concurrency-safe because it involves shared mutable state}}
3835
_ = refTypeThrowsProp // expected-error{{property access can throw, but it is not marked with 'try' and the error is not handled}}
3936

4037

4138
_ = refTypeAsyncProp // expected-error {{property access is 'async' but is not marked with 'await'}}
42-
}
39+
}

0 commit comments

Comments
 (0)