Skip to content

Commit 4bddb3a

Browse files
Merge pull request #80427 from AnthonyLatsis/alcer-americanus
[SE-0461] Consistently diagnose protocol requirements in migration (adoption) mode
2 parents fdc0ba2 + e9406e0 commit 4bddb3a

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -2367,10 +2367,12 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
23672367
(void) VD->isObjC();
23682368
(void) VD->isDynamic();
23692369

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

23762378
// If this is a member of a nominal type, don't allow it to have a name of

test/Concurrency/attr_execution/adoption_mode.swift

+46-2
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,33 @@ do {
3939
}
4040

4141
protocol P {
42-
// FIXME: Not diagnosed
42+
init(sync: ())
43+
@execution(concurrent) init(executionAsync: ()) async
44+
@MainActor init(mainActorAsync: ()) async
45+
// 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}}
46+
init(async: ()) async
47+
48+
func syncF()
49+
@execution(concurrent) func executionAsyncF() async
50+
@MainActor func mainActorAsyncF() async
51+
// 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}}
4352
func asyncF() async
4453
}
4554
}
55+
protocol Functions {}
56+
extension Functions {
57+
init(sync: ()) {}
58+
@execution(concurrent) init(executionAsync: ()) async {}
59+
@MainActor init(mainActorAsync: ()) async {}
60+
// 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}}
61+
init(async: ()) async {}
62+
63+
func syncF() {}
64+
@execution(concurrent) func executionAsyncF() async {}
65+
@MainActor func mainActorAsyncF() async {}
66+
// 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}}
67+
func asyncF() async {}
68+
}
4669

4770
// MARK: Storage
4871
do {
@@ -81,10 +104,31 @@ do {
81104

82105
// 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}}
83106
var asyncS: Int { get async }
84-
// FIXME: Not diagnosed
107+
// 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}}
85108
subscript(asyncS _: Int) -> Int { get async }
86109
}
87110
}
111+
protocol Storage {}
112+
extension Storage {
113+
var syncS: Int { get {} set {} }
114+
subscript(syncS _: Int) -> Int { get {} }
115+
116+
@execution(concurrent) var executionAsyncS: Int { get async {} }
117+
@execution(concurrent) subscript(executionAsyncS _: Int) -> Int { get async {} }
118+
119+
@MainActor var mainActorAsyncS: Int { get async {} }
120+
@MainActor subscript(mainActorAsyncS _: Int) -> Int { get async {} }
121+
122+
// 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}}
123+
var asyncS: Int {
124+
get async {}
125+
}
126+
// 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}}
127+
subscript(asyncS _: Int) -> Int {
128+
get async throws {}
129+
}
130+
}
131+
88132

89133
// MARK: Parameters
90134
do {

0 commit comments

Comments
 (0)