Skip to content

Commit 80a8a07

Browse files
authored
Replace uses of the word "accessor" in diagnostics with user-facing terminology (#74462)
In this PR i worked on replacing the word accessor in diagnostics with more user-facing terminologies like setter, getter, didSet Observer, and members based on the context of the message. in some messages i didn't need to pass DescriptiveDeclKind instead i just changed the text copy itself. i also updated tests, so you might find it easier to check my changes this way. Please let me know if there's something i should've done in a better way, and request changes if needed. ! i can squash my commits after reviewing getting the PR Reviewed, just to make it easier to be checked commit by commit Resolves #55887
1 parent 73e859a commit 80a8a07

File tree

11 files changed

+34
-30
lines changed

11 files changed

+34
-30
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3963,8 +3963,8 @@ ERROR(attr_incompatible_with_objc,none,
39633963
(DeclAttribute, DescriptiveDeclKind))
39643964

39653965
ERROR(final_not_on_accessors,none,
3966-
"'final' cannot be applied to accessors, it must be put on the "
3967-
"%select{var|let|subscript}0", (unsigned))
3966+
"only the %select{property|subscript}0 itself can be marked as 'final'"
3967+
,(bool))
39683968

39693969
ERROR(override_rethrows_with_non_rethrows,none,
39703970
"override of 'rethrows' %select{method|initializer}0 should also "
@@ -4996,8 +4996,8 @@ NOTE(candidate_is_not_assignable,none,
49964996
(const ValueDecl *))
49974997

49984998
NOTE(change_to_mutating,none,
4999-
"mark %select{method|accessor}0 'mutating' to make 'self' mutable",
5000-
(bool))
4999+
"mark %select{method|%1}0 'mutating' to make 'self' mutable",
5000+
(bool, StringRef))
50015001
NOTE(masked_mutable_property,none,
50025002
"add explicit '%0' to refer to mutable %1 of %2",
50035003
(StringRef, DescriptiveDeclKind, Type))
@@ -6361,9 +6361,8 @@ NOTE(objc_witness_objc_requirement,none,
63616361
ERROR(no_opaque_return_type_of,none,
63626362
"unable to resolve type for _opaqueReturnTypeOf attribute", ())
63636363

6364-
63656364
ERROR(objc_observing_accessor, none,
6366-
"observing accessors are not allowed to be marked @objc", ())
6365+
"observers (%0) are not allowed to be marked '@objc'", (DescriptiveDeclKind))
63676366
ERROR(objc_init_accessor, none,
63686367
"init accessors cannot be marked @objc", ())
63696368
ERROR(objc_addressor, none,
@@ -7180,8 +7179,8 @@ ERROR(property_wrapper_computed, none,
71807179
"property wrapper cannot be applied to a computed property",
71817180
())
71827181
ERROR(property_wrapper_effectful,none,
7183-
"property wrappers currently cannot define an 'async' or 'throws' accessor",
7184-
())
7182+
"property wrapper's 'wrappedValue' property cannot define an 'async' or 'throws' %0",
7183+
(DescriptiveDeclKind))
71857184

71867185
ERROR(property_with_wrapper_conflict_attribute,none,
71877186
"property %0 with a wrapper cannot also be "
@@ -7593,7 +7592,7 @@ ERROR(invalid_decl_in_macro_expansion,none,
75937592
"macro expansion cannot introduce %0",
75947593
(DescriptiveDeclKind))
75957594
ERROR(let_accessor_expansion,none,
7596-
"cannot expand accessors on variable declared with 'let'",
7595+
"cannot expand accessor macro on variable declared with 'let'",
75977596
())
75987597
ERROR(invalid_main_type_in_macro_expansion,none,
75997598
"macro expansion cannot introduce '@main' type",

lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8394,8 +8394,9 @@ void VarDecl::emitLetToVarNoteIfSimple(DeclContext *UseDC) const {
83948394
}
83958395

83968396
auto &d = getASTContext().Diags;
8397+
auto descriptiveKindName = Decl::getDescriptiveKindName(FD->getDescriptiveKind());
83978398
auto diags = d.diagnose(FD->getFuncLoc(), diag::change_to_mutating,
8398-
isa<AccessorDecl>(FD));
8399+
isa<AccessorDecl>(FD), descriptiveKindName);
83998400
if (auto nonmutatingAttr =
84008401
FD->getAttrs().getAttribute<NonMutatingAttr>()) {
84018402
diags.fixItReplace(nonmutatingAttr->getLocation(), "mutating");

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,13 @@ void AttributeChecker::visitObjCAttr(ObjCAttr *attr) {
13791379
if (!checkObjCDeclContext(D))
13801380
error = diag::invalid_objc_decl_context;
13811381
else if (auto accessor = dyn_cast<AccessorDecl>(func))
1382-
if (!accessor->isGetterOrSetter())
1383-
error = diag::objc_observing_accessor;
1382+
if (!accessor->isGetterOrSetter()) {
1383+
auto declKind = accessor->getDescriptiveKind();
1384+
diagnoseAndRemoveAttr(attr, diag::objc_observing_accessor, declKind)
1385+
.limitBehavior(behavior);
1386+
reason.describe(D);
1387+
return;
1388+
}
13841389
} else if (isa<ConstructorDecl>(D) ||
13851390
isa<DestructorDecl>(D) ||
13861391
isa<SubscriptDecl>(D) ||
@@ -2584,10 +2589,8 @@ void AttributeChecker::visitFinalAttr(FinalAttr *attr) {
25842589

25852590
if (auto *accessor = dyn_cast<AccessorDecl>(D)) {
25862591
if (!attr->isImplicit()) {
2587-
unsigned Kind = 2;
2588-
if (auto *VD = dyn_cast<VarDecl>(accessor->getStorage()))
2589-
Kind = VD->isLet() ? 1 : 0;
2590-
diagnose(attr->getLocation(), diag::final_not_on_accessors, Kind)
2592+
diagnose(attr->getLocation(), diag::final_not_on_accessors,
2593+
isa<VarDecl>(accessor->getStorage()))
25912594
.fixItRemove(attr->getRange());
25922595
return;
25932596
}

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,8 @@ bool swift::isRepresentableInObjC(
681681
// willSet/didSet implementations are never exposed to objc, they are
682682
// always directly dispatched from the synthesized setter.
683683
diagnoseAndRemoveAttr(accessor, Reason.getAttr(),
684-
diag::objc_observing_accessor)
684+
diag::objc_observing_accessor,
685+
accessor->getDescriptiveKind())
685686
.limitBehavior(behavior);
686687
Reason.describe(accessor);
687688
return false;

lib/Sema/TypeCheckPropertyWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static VarDecl *findValueProperty(ASTContext &ctx, NominalTypeDecl *nominal,
108108

109109
// The property may not have any effects right now.
110110
if (auto getter = var->getEffectfulGetAccessor()) {
111-
getter->diagnose(diag::property_wrapper_effectful);
111+
getter->diagnose(diag::property_wrapper_effectful, getter->getDescriptiveKind());
112112
return nullptr;
113113
}
114114

test/Macros/accessor_macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,6 @@ macro addGetterMacro() =
171171
#if TEST_DIAGNOSTICS
172172
struct S {
173173
@addGetterMacro let x: Int
174-
// expected-warning@-1 {{cannot expand accessors on variable declared with 'let'; this is an error in the Swift 6 language mode}}
174+
// expected-warning@-1 {{cannot expand accessor macro on variable declared with 'let'; this is an error in the Swift 6 language mode}}
175175
}
176176
#endif

test/Sema/immutability.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ struct SomeStruct {
149149

150150
var p: Int {
151151
// Getters default to non-mutating.
152-
get { // expected-note {{mark accessor 'mutating' to make 'self' mutable}} {{5-5=mutating }}
152+
get { // expected-note {{mark getter 'mutating' to make 'self' mutable}} {{5-5=mutating }}
153153
iv = 37 // expected-error {{cannot assign to property: 'self' is immutable}}
154154
return 42
155155
}
@@ -168,13 +168,13 @@ struct SomeStruct {
168168
return 42
169169
}
170170
nonmutating
171-
set { // expected-note {{mark accessor 'mutating' to make 'self' mutable}} {{-1:5-16=mutating}}
171+
set { // expected-note {{mark setter 'mutating' to make 'self' mutable}} {{-1:5-16=mutating}}
172172
iv = newValue // expected-error {{cannot assign to property: 'self' is immutable}}
173173
}
174174
}
175175

176176
var r : Int {
177-
get { // expected-note {{mark accessor 'mutating' to make 'self' mutable}} {{5-5=mutating }}
177+
get { // expected-note {{mark getter 'mutating' to make 'self' mutable}} {{5-5=mutating }}
178178
iv = 37 // expected-error {{cannot assign to property: 'self' is immutable}}
179179
return 42
180180
}
@@ -708,7 +708,7 @@ extension JustAProtocol {
708708
var foo: String {
709709
get { return name }
710710
nonmutating set { name = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
711-
// expected-note@-1 {{mark accessor 'mutating' to make 'self' mutable}}{{5-16=mutating}}
711+
// expected-note@-1 {{mark setter 'mutating' to make 'self' mutable}}{{5-16=mutating}}
712712
}
713713

714714
nonmutating func bar() { // expected-note {{mark method 'mutating' to make 'self' mutable}}{{3-14=mutating}}

test/attr/attr_objc.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ class subject_getterSetter1 {
142142
}
143143

144144
var observingAccessorsVar1: Int = 0 {
145-
@objc // expected-error {{observing accessors are not allowed to be marked @objc}} {{5-11=}}
145+
@objc // expected-error {{observers (willSet observer) are not allowed to be marked '@objc'}} {{5-11=}}
146146
willSet {
147147
}
148-
@objc // expected-error {{observing accessors are not allowed to be marked @objc}} {{5-11=}}
148+
@objc // expected-error {{observers (didSet observer) are not allowed to be marked '@objc'}} {{5-11=}}
149149
didSet {
150150
}
151151
}
@@ -2091,7 +2091,7 @@ class BadClass2 {
20912091
}
20922092

20932093
var prop3: Int {
2094-
@objc(setProperty:) // expected-error{{observing accessors are not allowed to be marked @objc}} {{5-25=}}
2094+
@objc(setProperty:) // expected-error{{observers (didSet observer) are not allowed to be marked '@objc'}} {{5-25=}}
20952095
didSet { }
20962096
}
20972097
}

test/decl/ext/extensions.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ extension DoesNotImposeClassReq_2 where Self : AnyObject {
200200
var wrappingProperty1: String {
201201
get { property }
202202
set { property = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
203-
// expected-note@-1 {{mark accessor 'mutating' to make 'self' mutable}}{{5-5=mutating }}
203+
// expected-note@-1 {{mark setter 'mutating' to make 'self' mutable}}{{5-5=mutating }}
204204
}
205205

206206
var wrappingProperty2: String {
207207
get { property }
208208
nonmutating set { property = newValue } // expected-error {{cannot assign to property: 'self' is immutable}}
209-
// expected-note@-1 {{mark accessor 'mutating' to make 'self' mutable}}{{5-16=mutating}}
209+
// expected-note@-1 {{mark setter 'mutating' to make 'self' mutable}}{{5-16=mutating}}
210210
}
211211

212212
var wrappingProperty3: String {

test/decl/subscript/subscripting.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ struct MutableComputedGetter {
320320
struct MutableSubscriptInGetter {
321321
var value: Int
322322
subscript(index: Int) -> Int {
323-
get { // expected-note {{mark accessor 'mutating' to make 'self' mutable}}
323+
get { // expected-note {{mark getter 'mutating' to make 'self' mutable}}
324324
value = 5 // expected-error{{cannot assign to property: 'self' is immutable}}
325325
return 5
326326
}

test/decl/var/effectful_property_wrapper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct Abstraction<T> {
1010
init(_ initial : T) { self.value = initial }
1111

1212
var wrappedValue : T {
13-
get throws { return value } // expected-error{{property wrappers currently cannot define an 'async' or 'throws' accessor}}
13+
get throws { return value } // expected-error{{property wrapper's 'wrappedValue' property cannot define an 'async' or 'throws' getter}}
1414
}
1515

1616
// its OK to have effectful props that are not `wrappedValue`

0 commit comments

Comments
 (0)