Skip to content
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
12 changes: 7 additions & 5 deletions lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4666,13 +4666,15 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
void diagnoseRedundantAwait(AwaitExpr *E) const {
if (auto *SVE = SingleValueStmtExpr::tryDigOutSingleValueStmtExpr(E)) {
// For an if/switch expression, produce a tailored warning.
Ctx.Diags.diagnose(E->getAwaitLoc(),
diag::effect_marker_on_single_value_stmt,
"await", SVE->getStmt()->getKind())
.highlight(E->getAwaitLoc());
Ctx.Diags
.diagnose(E->getAwaitLoc(), diag::effect_marker_on_single_value_stmt,
"await", SVE->getStmt()->getKind())
.highlight(E->getAwaitLoc())
.fixItRemove(E->getAwaitLoc());
return;
}
Ctx.Diags.diagnose(E->getAwaitLoc(), diag::no_async_in_await);
Ctx.Diags.diagnose(E->getAwaitLoc(), diag::no_async_in_await)
.fixItRemove(E->getAwaitLoc());
}

void diagnoseRedundantUnsafe(UnsafeExpr *E) const {
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/actor_call_implicitly_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ actor BankAccount {
}

func testSelfBalance() async {
_ = await balance() // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await balance() // expected-warning {{no 'async' operations occur within 'await' expression}}{{9-15=}}
}

// returns the amount actually withdrawn
Expand Down Expand Up @@ -357,12 +357,12 @@ actor Calculator {
// We will error on the next line when we get past type checking. But since we
// error in the type checker, we do not make further progress.
let _ = (await bananaAdd(1))(2)
let _ = await (await bananaAdd(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}
let _ = await (await bananaAdd(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}{{11-17=}}

let calc = Calculator()

let _ = (await calc.addCurried(1))(2)
let _ = await (await calc.addCurried(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}
let _ = await (await calc.addCurried(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}{{11-17=}}

let plusOne = await calc.addCurried(await calc.add(0, 1))
let _ = plusOne(2)
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/actor_existentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ actor Act {
nonisolated let act = Act()

func bad() async {
// expected-warning@+3 {{no 'async' operations occur within 'await' expression}}
// expected-warning@+3 {{no 'async' operations occur within 'await' expression}}{{5-11=}}
// expected-error@+2 {{actor-isolated property 'i' can not be mutated from a nonisolated context}}
// expected-note@+1 {{consider declaring an isolated method on 'Act' to perform the mutation}}
await act.i = 666
Expand All @@ -66,13 +66,13 @@ protocol Proto: Actor {
extension Act: Proto {}

func good() async {
// expected-warning@+3 {{no 'async' operations occur within 'await' expression}}
// expected-warning@+3 {{no 'async' operations occur within 'await' expression}}{{5-11=}}
// expected-error@+2 {{actor-isolated property 'i' can not be mutated from a nonisolated context}}
// expected-note@+1 {{consider declaring an isolated method on 'Proto' to perform the mutation}}
await (act as any Proto).i = 42
let aIndirect: any Proto = act

// expected-warning@+3 {{no 'async' operations occur within 'await' expression}}
// expected-warning@+3 {{no 'async' operations occur within 'await' expression}}{{5-11=}}
// expected-error@+2 {{actor-isolated property 'i' can not be mutated from a nonisolated context}}
// expected-note@+1 {{consider declaring an isolated method on 'Proto' to perform the mutation}}
await aIndirect.i = 777
Expand Down
6 changes: 3 additions & 3 deletions test/Concurrency/actor_isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ extension MyActor {
// expected-note@-1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
acceptInout(&otherActor.mutable) // expected-error{{actor-isolated property 'mutable' can not be used 'inout' on a nonisolated actor instance}}
// expected-error@+3{{actor-isolated property 'mutable' can not be mutated on a nonisolated actor instance}}
// expected-warning@+2{{no 'async' operations occur within 'await' expression}}
// expected-warning@+2{{no 'async' operations occur within 'await' expression}}{{5-11=}}
// expected-note@+1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
await otherActor.mutable = 0

Expand Down Expand Up @@ -616,7 +616,7 @@ func testGlobalRestrictions(actor: MyActor) async {

// stored and computed properties can be accessed. Only immutable stored properties can be accessed without 'await'
_ = actor.immutable
_ = await actor.immutable // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await actor.immutable // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
_ = actor.mutable // expected-error{{actor-isolated property 'mutable' cannot be accessed from outside of the actor}}{{7-7=await }}
_ = await actor.mutable
_ = actor.text[0] // expected-error{{actor-isolated property 'text' cannot be accessed from outside of the actor}}{{7-7=await }}
Expand Down Expand Up @@ -1205,7 +1205,7 @@ extension MyActor {
}

acceptAsyncSendableClosureInheriting {
_ = await synchronous() // expected-warning{{no 'async' operations occur within 'await' expression}}
_ = await synchronous() // expected-warning{{no 'async' operations occur within 'await' expression}}{{11-17=}}
counter += 1 // okay
}

Expand Down
8 changes: 4 additions & 4 deletions test/Concurrency/actor_isolation_swift6.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ func checkIsolationValueType(_ formance: InferredFromConformance,
_ = anno.counter

// make sure it's just a warning if someone was awaiting on it previously
_ = await ext.point // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await formance.counter // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await anno.counter // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await ext.point // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
_ = await formance.counter // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
_ = await anno.counter // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}

// this does not need an await, since the property is 'Sendable' and of a
// value type
_ = anno.point
_ = await anno.point
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}{{7-13=}}

// these do need await, regardless of reference or value type
_ = await (formance as any MainCounter).counter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct Kappa {
// though we could try to could give a better message
if let await maybeData { // expected-error{{unwrap condition requires a valid identifier}}
// expected-error@-1{{pattern variable binding cannot appear in an expression}}
// expected-warning@-2{{no 'async' operations occur within 'await' expression}}
// expected-warning@-2{{no 'async' operations occur within 'await' expression}}{{12-18=}}
return maybeData // expected-error{{expression is 'async' but is not marked with 'await'}}
// expected-note@-1{{property access is 'async'}}
}
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/global_actor_inference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ func acceptAsyncSendableClosureInheriting<T>(@_inheritActorContext _: @Sendable
}

acceptAsyncSendableClosureInheriting {
await onlyOnMainActor() // expected-warning{{no 'async' operations occur within 'await' expression}}
await onlyOnMainActor() // expected-warning{{no 'async' operations occur within 'await' expression}}{{5-11=}}
}
}

Expand Down
10 changes: 5 additions & 5 deletions test/Concurrency/reasync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func asyncFunction() async {}

func callReasyncFunction() async {
reasyncFunction { }
await reasyncFunction { } // expected-warning {{no 'async' operations occur within 'await' expression}}
await reasyncFunction { } // expected-warning {{no 'async' operations occur within 'await' expression}}{{3-9=}}

reasyncFunction { await asyncFunction() }
// expected-error@-1:3 {{expression is 'async' but is not marked with 'await'}}{{3-3=await }}
Expand All @@ -58,11 +58,11 @@ enum HorseError : Error {
func callReasyncRethrowsFunction() async throws {
reasyncRethrowsFunction { }
await reasyncRethrowsFunction { }
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}{{3-9=}}
try reasyncRethrowsFunction { }
// expected-warning@-1 {{no calls to throwing functions occur within 'try' expression}}
try await reasyncRethrowsFunction { }
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}{{7-13=}}
// expected-warning@-2 {{no calls to throwing functions occur within 'try' expression}}

reasyncRethrowsFunction { await asyncFunction() }
Expand All @@ -84,10 +84,10 @@ func callReasyncRethrowsFunction() async throws {
await reasyncRethrowsFunction { throw HorseError.colic }
// expected-error@-1 {{call can throw but is not marked with 'try'}}
// expected-note@-2 {{call is to 'rethrows' function, but argument function can throw}}
// expected-warning@-3 {{no 'async' operations occur within 'await' expression}}
// expected-warning@-3 {{no 'async' operations occur within 'await' expression}}{{3-9=}}
try reasyncRethrowsFunction { throw HorseError.colic }
try await reasyncRethrowsFunction { throw HorseError.colic }
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}
// expected-warning@-1 {{no 'async' operations occur within 'await' expression}}{{7-13=}}

reasyncRethrowsFunction { await asyncFunction(); throw HorseError.colic }
// expected-error@-1 {{call can throw but is not marked with 'try'}}
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/toplevel/no-async-5-top-level.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func isolatedSync() { // expected-note 2 {{calls to global function 'isolatedSyn
}

func nonIsolatedAsync() async {
await print(a) // expected-warning {{no 'async' operations occur within 'await' expression}}
await print(a) // expected-warning {{no 'async' operations occur within 'await' expression}}{{5-11=}}
a = a + 10
}

Expand Down
4 changes: 2 additions & 2 deletions test/Concurrency/transfernonsendable_rbi_result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ func testActorCrossingBoundary() async {
let _ = await (await mainActorResult(1))(2)
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from main actor-isolated global function 'mainActorResult' to global actor 'CustomActor'-isolated context}}
// expected-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
// expected-warning @-3 {{no 'async' operations occur within 'await' expression}}
// expected-warning @-3 {{no 'async' operations occur within 'await' expression}}{{11-17=}}

let calc = Calculator()

let _ = (await calc.addCurried(1))(2)
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from actor-isolated instance method 'addCurried' to global actor 'CustomActor'-isolated context}}
// expected-note@-2{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
let _ = await (await calc.addCurried(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}
let _ = await (await calc.addCurried(1))(2) // expected-warning{{no 'async' operations occur within 'await' expression}}{{11-17=}}
// expected-error @-1 {{non-Sendable '(Int) -> Int'-typed result can not be returned from actor-isolated instance method 'addCurried' to global actor 'CustomActor'-isolated context}}
// expected-note @-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}

Expand Down
2 changes: 1 addition & 1 deletion test/Distributed/distributed_protocol_isolation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func outside_good_generic<DP: DistProtocol>(dp: DP) async throws {
_ = dp.local() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
_ = await dp.local() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
// the below warning is expected because we don't apply the "implicitly async" to the not-callable func
// expected-warning@-2{{no 'async' operations occur within 'await' expression}}
// expected-warning@-2{{no 'async' operations occur within 'await' expression}}{{7-13=}}

_ = try dp.local() // expected-error{{only 'distributed' instance methods can be called on a potentially remote distributed actor}}
// the below warning is expected because we don't apply the "implicitly throwing" to the not-callable func
Expand Down
2 changes: 1 addition & 1 deletion test/StringProcessing/Parse/forward-slash-regex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ do {
// expected-warning@-1 {{no calls to throwing functions occur within 'try' expression}}
} // expected-error {{expected expression after operator}}

_ = await /x/ // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await /x/ // expected-warning {{no 'async' operations occur within 'await' expression}}{{5-11=}}

/x/ = 0 // expected-error {{cannot assign to value: literals are not mutable}}
/x/() // expected-error {{cannot call value of non-function type 'Regex<Substring>'}}
Expand Down
2 changes: 1 addition & 1 deletion test/decl/protocol/effectful_properties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func composed2<U : None & A >(u : U) async {
_ = u.someProp
// FIXME: this ^ should raise "property access is 'async' but is not marked with 'await'""

_ = await u.someProp // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await u.someProp // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
}

func composed3<U : T & None >(u : U) throws {
Expand Down
29 changes: 27 additions & 2 deletions test/expr/unary/async_await.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// RUN: %target-swift-frontend -typecheck -verify %s -disable-availability-checking
// RUN: %target-typecheck-verify-swift -disable-availability-checking

// REQUIRES: concurrency

func test1(asyncfp : () async -> Int, fp : () -> Int) async {
_ = await asyncfp()
_ = await asyncfp() + asyncfp()
_ = await asyncfp() + fp()
_ = await fp() + 42 // expected-warning {{no 'async' operations occur within 'await' expression}}
_ = await fp() + 42 // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
_ = 32 + asyncfp() + asyncfp() // expected-error {{expression is 'async' but is not marked with 'await'}}{{7-7=await }}
// expected-note@-1:12{{call is 'async'}}
// expected-note@-2:24{{call is 'async'}}
Expand Down Expand Up @@ -239,3 +239,28 @@ func testAsyncExprWithoutAwait() async {
// expected-warning@-1 {{initialization of immutable value 'a' was never used; consider replacing with assignment to '_' or removing it}}
// expected-note@-2 {{call is 'async'}}
}

// https://github.com/swiftlang/swift/issues/85818
func testNoAsyncInAwait() async {
func g() {}
await g() // expected-warning {{no 'async' operations occur within 'await' expression}}{{3-9=}}
_ = (g(), await (g())) // expected-warning {{no 'async' operations occur within 'await' expression}}{{13-19=}}

@MainActor struct MA {
func f() {}
func g() async {
await f() // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
}

static func h(_ ma: MA) async {
await ma.f() // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
}
}

actor A {
func f() {}
func g() async {
await f() // expected-warning {{no 'async' operations occur within 'await' expression}}{{7-13=}}
}
}
}
Loading