Skip to content

Commit 66d307e

Browse files
committed
Improve implicit async error message
At the declaration, the implicitly async functions appear to be synchronous, so it isn't clear why the error message is being emitted. This patch updates the error message to indicate that the function is implicitly asynchronous.
1 parent c2eda02 commit 66d307e

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4207,8 +4207,9 @@ ERROR(actor_isolated_self_independent_context,none,
42074207
"'@actorIndependent' context",
42084208
(DescriptiveDeclKind, DeclName))
42094209
ERROR(actor_isolated_inout_state,none,
4210-
"actor-isolated %0 %1 cannot be passed 'inout' to asynchronous function",
4211-
(DescriptiveDeclKind, DeclName))
4210+
"actor-isolated %0 %1 cannot be passed 'inout' to"
4211+
"%select{| implicitly}2 'async' function call",
4212+
(DescriptiveDeclKind, DeclName, bool))
42124213
ERROR(actor_isolated_mutating_func,none,
42134214
"cannot call mutating async function %0 on actor-isolated %1 %2",
42144215
(DeclName, DescriptiveDeclKind, DeclName))

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,8 @@ namespace {
930930
} else {
931931
ctx.Diags.diagnose(
932932
subArg->getLoc(), diag::actor_isolated_inout_state,
933-
memberDecl->getDescriptiveKind(), memberDecl->getName());
933+
memberDecl->getDescriptiveKind(), memberDecl->getName(),
934+
call->implicitlyAsync());
934935
return true;
935936
}
936937
}

test/Concurrency/actor_inout_isolation.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,24 @@ extension TestActor {
3636

3737
// Can't pass actor-isolated primitive into a function
3838
func inoutAsyncFunctionCall() async {
39-
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to asynchronous function}}
39+
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
4040
await modifyAsynchronously(&value1)
4141
}
4242

4343
func inoutAsyncClosureCall() async {
44-
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to asynchronous function}}
44+
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
4545
await { (_ foo: inout Int) async in foo += 1 }(&value1)
4646
}
4747

4848
// Can't pass actor-isolated primitive into first-class function value
4949
func inoutAsyncValueCall() async {
50-
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to asynchronous function}}
50+
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
5151
await modifyAsyncValue(&value1)
5252
}
5353

5454
// Can't pass property of actor-isolated state inout to async function
5555
func inoutPropertyStateValueCall() async {
56-
// expected-error@+1{{actor-isolated property 'position' cannot be passed 'inout' to asynchronous function}}
56+
// expected-error@+1{{actor-isolated property 'position' cannot be passed 'inout' to 'async' function call}}
5757
await modifyAsynchronously(&position.x)
5858
}
5959
}
@@ -65,7 +65,7 @@ extension TestActor {
6565
}
6666

6767
func passStateIntoMethod() async {
68-
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to asynchronous function}}
68+
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
6969
await modifyByValue(&value1)
7070
}
7171
}
@@ -88,23 +88,23 @@ extension TestActor {
8888
func passStateIntoDifferentClassMethod() async {
8989
let other = NonAsyncClass()
9090
let otherCurry = other.modifyOtherAsync
91-
// expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to asynchronous function}}
91+
// expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to 'async' function call}}
9292
await other.modifyOtherAsync(&value2)
93-
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to asynchronous function}}
93+
// expected-error@+1{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
9494
await otherCurry(&value1)
9595
other.modifyOtherNotAsync(&value2) // This is okay since it's not async!
9696

9797
}
9898

9999
func callMutatingFunctionOnStruct() async {
100100
// expected-error@+3:20{{cannot call mutating async function 'setComponents(x:y:)' on actor-isolated property 'position'}}
101-
// expected-error@+2:51{{actor-isolated property 'nextPosition' cannot be passed 'inout' to asynchronous function}}
102-
// expected-error@+1:71{{actor-isolated property 'nextPosition' cannot be passed 'inout' to asynchronous function}}
101+
// expected-error@+2:51{{actor-isolated property 'nextPosition' cannot be passed 'inout' to 'async' function call}}
102+
// expected-error@+1:71{{actor-isolated property 'nextPosition' cannot be passed 'inout' to 'async' function call}}
103103
await position.setComponents(x: &nextPosition.x, y: &nextPosition.y)
104104

105105
// expected-error@+3:20{{cannot call mutating async function 'setComponents(x:y:)' on actor-isolated property 'position'}}
106-
// expected-error@+2:38{{actor-isolated property 'value1' cannot be passed 'inout' to asynchronous function}}
107-
// expected-error@+1:50{{actor-isolated property 'value2' cannot be passed 'inout' to asynchronous function}}
106+
// expected-error@+2:38{{actor-isolated property 'value1' cannot be passed 'inout' to 'async' function call}}
107+
// expected-error@+1:50{{actor-isolated property 'value2' cannot be passed 'inout' to 'async' function call}}
108108
await position.setComponents(x: &value1, y: &value2)
109109
}
110110
}
@@ -120,14 +120,14 @@ extension TestActor {
120120
// Actor state passed inout to implicitly async function on an actor of the
121121
// same type
122122
func modifiedByOtherTestActor(_ other: TestActor) async {
123-
//expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to asynchronous function}}
123+
//expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to implicitly 'async' function call}}
124124
await other.modify(&value2)
125125
}
126126

127127
// Actor state passed inout to an implicitly async function on an actor of a
128128
// different type
129129
func modifiedByOther(_ other: DifferentActor) async {
130-
//expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to asynchronous function}}
130+
//expected-error@+1{{actor-isolated property 'value2' cannot be passed 'inout' to implicitly 'async' function call}}
131131
await other.modify(&value2)
132132
}
133133
}

0 commit comments

Comments
 (0)