Skip to content

Commit 78adeb6

Browse files
authored
Incorrect location of 'async' for protocol in actor's fix suggestion (#69246)
* implementing changes and tests * added unit test using throws * adding test with distributed actor * moved distributed-actor tests to another file * revert import Distributed
1 parent ad30745 commit 78adeb6

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,12 +3288,6 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
32883288
} else if (requirementAbstractFunc->getThrowsLoc().isValid()) {
32893289
// Insert before the "throws" (we only have async)".
32903290
insertLoc = requirementAbstractFunc->getThrowsLoc();
3291-
} else if (auto requirementFunc =
3292-
dyn_cast<FuncDecl>(requirementAbstractFunc)) {
3293-
// Insert before the result type, if there is one.
3294-
if (auto resultTypeRepr = requirementFunc->getResultTypeRepr()) {
3295-
insertLoc = resultTypeRepr->getStartLoc();
3296-
}
32973291
}
32983292

32993293
// Insert after the parentheses.

test/decl/class/actor/conformance.swift

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ protocol SyncProtocol {
2222

2323
func syncMethodC() -> Int
2424

25+
func syncMethodE() -> Void // expected-note{{mark the protocol requirement 'syncMethodE()' 'async' to allow actor-isolated conformances}}{{21-21= async}}
26+
27+
func syncMethodF(param: String) -> Int // expected-note{{mark the protocol requirement 'syncMethodF(param:)' 'async' to allow actor-isolated conformances}}{{34-34= async}}
28+
29+
func syncMethodG() throws -> Void // expected-note{{mark the protocol requirement 'syncMethodG()' 'async' to allow actor-isolated conformances}}{{22-22=async }}
30+
2531
subscript (index: Int) -> String { get } // expected-note{{'subscript(_:)' declared here}}
2632

2733
static func staticMethod()
@@ -44,6 +50,18 @@ actor OtherActor: SyncProtocol {
4450
// FIXME: Consider suggesting nonisolated if this didn't match.
4551
nonisolated func syncMethodC() -> Int { 5 }
4652

53+
func syncMethodE() -> Void { }
54+
// expected-error@-1{{actor-isolated instance method 'syncMethodE()' cannot be used to satisfy nonisolated protocol requirement}}
55+
// expected-note@-2{{add 'nonisolated' to 'syncMethodE()' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
56+
57+
func syncMethodF(param: String) -> Int { 5 }
58+
// expected-error@-1{{actor-isolated instance method 'syncMethodF(param:)' cannot be used to satisfy nonisolated protocol requirement}}
59+
// expected-note@-2{{add 'nonisolated' to 'syncMethodF(param:)' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
60+
61+
func syncMethodG() { }
62+
// expected-error@-1{{actor-isolated instance method 'syncMethodG()' cannot be used to satisfy nonisolated protocol requirement}}
63+
// expected-note@-2{{add 'nonisolated' to 'syncMethodG()' to make this instance method not isolated to the actor}}{{3-3=nonisolated }}
64+
4765
subscript (index: Int) -> String { "\(index)" }
4866
// expected-error@-1{{actor-isolated subscript 'subscript(_:)' cannot be used to satisfy nonisolated protocol requirement}}
4967
// expected-note@-2{{add 'nonisolated' to 'subscript(_:)' to make this subscript not isolated to the actor}}{{3-3=nonisolated }}
@@ -77,4 +95,4 @@ actor A2: Initializers {
7795
init(int: Int) { }
7896

7997
func withBells() async -> A2 { self }
80-
}
98+
}

test/decl/protocol/special/DistributedActor.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,16 @@ func testConformance() {
7474
acceptDistributedActor(D1.self)
7575
acceptAnyActor(D1.self)
7676
}
77+
78+
// https://github.com/apple/swift/issues/69244
79+
protocol P {
80+
func foo() -> Void
81+
// expected-note@-1{{mark the protocol requirement 'foo()' 'async throws' to allow actor-isolated conformances}}{{13-13= async throws}}
82+
}
83+
84+
distributed actor A: P {
85+
typealias ActorSystem = LocalTestingDistributedActorSystem
86+
distributed func foo() { }
87+
// expected-error@-1{{actor-isolated distributed instance method 'foo()' cannot be used to satisfy nonisolated protocol requirement}}
88+
}
89+
// ---

0 commit comments

Comments
 (0)