Skip to content

[SE-0461] Consistently diagnose protocol requirements in migration (adoption) mode #80427

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 1, 2025
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
6 changes: 4 additions & 2 deletions lib/Sema/TypeCheckDeclPrimary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,10 +2367,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
(void) VD->isObjC();
(void) VD->isDynamic();

// Check for actor isolation of top-level and local declarations.
// Check for actor isolation of top-level and local declarations, and
// protocol requirements.g
// Declarations inside types are handled in checkConformancesInContext()
// to avoid cycles involving associated type inference.
if (!VD->getDeclContext()->isTypeContext())
if (!VD->getDeclContext()->isTypeContext() ||
isa<ProtocolDecl>(VD->getDeclContext()))
(void) getActorIsolation(VD);

// If this is a member of a nominal type, don't allow it to have a name of
Expand Down
48 changes: 46 additions & 2 deletions test/Concurrency/attr_execution/adoption_mode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,33 @@ do {
}

protocol P {
// FIXME: Not diagnosed
init(sync: ())
@execution(concurrent) init(executionAsync: ()) async
@MainActor init(mainActorAsync: ()) async
// expected-warning@+1:5 {{feature 'AsyncCallerExecution' will cause nonisolated async initializer 'init' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{5-5=@execution(concurrent) }}{{none}}
init(async: ()) async

func syncF()
@execution(concurrent) func executionAsyncF() async
@MainActor func mainActorAsyncF() async
// expected-warning@+1:10 {{feature 'AsyncCallerExecution' will cause nonisolated async instance method 'asyncF' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{5-5=@execution(concurrent) }}{{none}}
func asyncF() async
}
}
protocol Functions {}
extension Functions {
init(sync: ()) {}
@execution(concurrent) init(executionAsync: ()) async {}
@MainActor init(mainActorAsync: ()) async {}
// expected-warning@+1:3 {{feature 'AsyncCallerExecution' will cause nonisolated async initializer 'init' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{3-3=@execution(concurrent) }}{{none}}
init(async: ()) async {}

func syncF() {}
@execution(concurrent) func executionAsyncF() async {}
@MainActor func mainActorAsyncF() async {}
// expected-warning@+1:8 {{feature 'AsyncCallerExecution' will cause nonisolated async instance method 'asyncF' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{3-3=@execution(concurrent) }}{{none}}
func asyncF() async {}
}

// MARK: Storage
do {
Expand Down Expand Up @@ -81,10 +104,31 @@ do {

// expected-warning@+1:23 {{feature 'AsyncCallerExecution' will cause nonisolated async getter for property 'asyncS' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{5-5=@execution(concurrent) }}{{none}}
var asyncS: Int { get async }
// FIXME: Not diagnosed
// expected-warning@+1:39 {{feature 'AsyncCallerExecution' will cause nonisolated async getter for subscript 'subscript' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{5-5=@execution(concurrent) }}{{none}}
subscript(asyncS _: Int) -> Int { get async }
}
}
protocol Storage {}
extension Storage {
var syncS: Int { get {} set {} }
subscript(syncS _: Int) -> Int { get {} }

@execution(concurrent) var executionAsyncS: Int { get async {} }
@execution(concurrent) subscript(executionAsyncS _: Int) -> Int { get async {} }

@MainActor var mainActorAsyncS: Int { get async {} }
@MainActor subscript(mainActorAsyncS _: Int) -> Int { get async {} }

// expected-warning@+2:5 {{feature 'AsyncCallerExecution' will cause nonisolated async getter for property 'asyncS' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{-1:3-3=@execution(concurrent) }}{{none}}
var asyncS: Int {
get async {}
}
// expected-warning@+2:5 {{feature 'AsyncCallerExecution' will cause nonisolated async getter for subscript 'subscript' to run on the caller's actor; use @execution(concurrent) to preserve behavior}}{{-1:3-3=@execution(concurrent) }}{{none}}
subscript(asyncS _: Int) -> Int {
get async throws {}
}
}


// MARK: Parameters
do {
Expand Down