Skip to content

Commit 9bb6b0d

Browse files
committed
Sema: Improve requirement indicator note for actor_isolated_witness
`x declared here` is not helpful and clear enough, especially when there are other notes attached. Swap it for a new note that says `requirement x declared here`.
1 parent 7d24c5f commit 9bb6b0d

File tree

7 files changed

+18
-11
lines changed

7 files changed

+18
-11
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ NOTE(opaque_return_type_declared_here,none,
4242
"opaque return type declared here", ())
4343
NOTE(default_value_declared_here,none,
4444
"default value declared here", ())
45+
NOTE(protocol_requirement_declared_here,none,
46+
"requirement %0 declared here", (const ValueDecl *))
4547

4648
//------------------------------------------------------------------------------
4749
// MARK: Constraint solver diagnostics

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,8 +3439,12 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
34393439
// If there are remaining options, they are missing async/throws on the
34403440
// requirement itself. If we have a source location for the requirement,
34413441
// provide those in a note.
3442-
if (missingOptions && requirement->getLoc().isValid() &&
3443-
isa<AbstractFunctionDecl>(requirement)) {
3442+
3443+
if (requirement->getLoc().isInvalid()) {
3444+
return std::nullopt;
3445+
}
3446+
3447+
if (missingOptions && isa<AbstractFunctionDecl>(requirement)) {
34443448
int suggestAddingModifiers = 0;
34453449
std::string modifiers;
34463450
if (missingOptions.contains(MissingFlags::RequirementAsync)) {
@@ -3486,7 +3490,8 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
34863490
diag.fixItInsert(insertLoc, modifiers);
34873491
}
34883492
} else {
3489-
requirement->diagnose(diag::decl_declared_here, requirement);
3493+
requirement->diagnose(diag::protocol_requirement_declared_here,
3494+
requirement);
34903495
}
34913496

34923497
return std::nullopt;

test/Concurrency/actor_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ class OverridesNonsiolatedInit: SuperWithNonisolatedInit {
16121612
class NonSendable {}
16131613

16141614
protocol NonisolatedProtocol {
1615-
var ns: NonSendable { get } // expected-note {{'ns' declared here}}
1615+
var ns: NonSendable { get } // expected-note {{requirement 'ns' declared here}}
16161616
}
16171617

16181618
actor ActorWithNonSendableLet: NonisolatedProtocol {

test/Concurrency/global_actor_inference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func testNotAllInP1(nap1: NotAllInP1) { // expected-note{{add '@SomeGlobalActor'
120120
// Make sure we don't infer 'nonisolated' for stored properties.
121121
@MainActor
122122
protocol Interface {
123-
nonisolated var baz: Int { get } // expected-note{{'baz' declared here}}
123+
nonisolated var baz: Int { get } // expected-note{{requirement 'baz' declared here}}
124124
}
125125

126126
@MainActor

test/Concurrency/preconcurrency_conformances.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct GlobalActor {
130130
protocol WithIndividuallyIsolatedRequirements {
131131
@MainActor var a: Int { get set }
132132
@GlobalActor var b: Int { get set }
133-
// expected-note@-1 {{'b' declared here}}
133+
// expected-note@-1 {{requirement 'b' declared here}}
134134

135135
@GlobalActor func test()
136136
// expected-note@-1 {{mark the protocol requirement 'test()' 'async' to allow actor-isolated conformances}}
@@ -158,7 +158,7 @@ do {
158158
@MainActor
159159
protocol WithNonIsolated {
160160
var prop: Int { get set }
161-
// expected-note@-1 {{'prop' declared here}}
161+
// expected-note@-1 {{requirement 'prop' declared here}}
162162
nonisolated func test()
163163
// expected-note@-1 {{mark the protocol requirement 'test()' 'async' to allow actor-isolated conformances}}
164164
}

test/decl/class/actor/conformance.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ extension MyActor: AsyncProtocol {
1515
}
1616

1717
protocol SyncProtocol {
18-
var propertyA: Int { get } // expected-note{{'propertyA' declared here}}
19-
var propertyB: Int { get set } // expected-note{{'propertyB' declared here}}
18+
var propertyA: Int { get } // expected-note{{requirement 'propertyA' declared here}}
19+
var propertyB: Int { get set } // expected-note{{requirement 'propertyB' declared here}}
2020

2121
func syncMethodA() // expected-note{{mark the protocol requirement 'syncMethodA()' 'async' to allow actor-isolated conformances}}{{21-21= async}}
2222

@@ -28,7 +28,7 @@ protocol SyncProtocol {
2828

2929
func syncMethodG() throws -> Void // expected-note{{mark the protocol requirement 'syncMethodG()' 'async' to allow actor-isolated conformances}}{{22-22=async }}
3030

31-
subscript (index: Int) -> String { get } // expected-note{{'subscript(_:)' declared here}}
31+
subscript (index: Int) -> String { get } // expected-note{{requirement 'subscript(_:)' declared here}}
3232

3333
static func staticMethod()
3434
static var staticProperty: Int { get }

test/decl/protocol/special/DistributedActor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ distributed actor D4 {
5555

5656
protocol P1: DistributedActor {
5757
distributed func dist() -> String
58-
// expected-note@-1{{'dist()' declared here}}
58+
// expected-note@-1{{requirement 'dist()' declared here}}
5959
}
6060

6161
distributed actor D5: P1 {

0 commit comments

Comments
 (0)