Skip to content

Only diagnose references to globals under -warn-concurrency. #36718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckConcurrency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ namespace {
///
/// \returns true if we diagnosed the entity, \c false otherwise.
bool diagnoseReferenceToUnsafeGlobal(ValueDecl *value, SourceLoc loc) {
if (!shouldDiagnoseExistingDataRaces(getDeclContext()))
if (!ctx.LangOpts.WarnConcurrency)
return false;

// Only diagnose direct references to mutable global state.
Expand Down
9 changes: 3 additions & 6 deletions test/decl/var/effectful_properties_global.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ var intAsyncProp : Int {
get async { 0 }
}

var intThrowsProp : Int { // expected-note 2 {{var declared here}}
var intThrowsProp : Int {
get throws { 0 }
}

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

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

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

var refTypeThrowsProp : C { // expected-note {{var declared here}}
var refTypeThrowsProp : C {
get throws { return C() }
}

Expand All @@ -34,9 +32,8 @@ var refTypeAsyncProp : C {
}

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


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