Skip to content

Commit d922944

Browse files
authored
Merge pull request #9976 from ahoppen/pdm-diagnostics2
Migration to DeclBaseName in diagnostic definitions
2 parents 992e1c0 + faa1720 commit d922944

File tree

11 files changed

+55
-49
lines changed

11 files changed

+55
-49
lines changed

include/swift/AST/DiagnosticEngine.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,12 @@ namespace swift {
123123
: Kind(DiagnosticArgumentKind::Unsigned), UnsignedVal(I) {
124124
}
125125

126-
DiagnosticArgument(DeclName I)
127-
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
128-
}
129-
126+
DiagnosticArgument(DeclName D)
127+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
128+
129+
DiagnosticArgument(DeclBaseName D)
130+
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(D) {}
131+
130132
DiagnosticArgument(Identifier I)
131133
: Kind(DiagnosticArgumentKind::Identifier), IdentifierVal(I) {
132134
}

include/swift/AST/DiagnosticsCommon.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ERROR(error_no_group_info,none,
5050

5151
NOTE(previous_decldef,none,
5252
"previous %select{declaration|definition}0 of %1 is here",
53-
(bool, Identifier))
53+
(bool, DeclBaseName))
5454

5555
NOTE(brace_stmt_suggest_do,none,
5656
"did you mean to use a 'do' statement?", ())

include/swift/AST/DiagnosticsSIL.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ ERROR(self_use_before_fully_init,none,
150150
"use of 'self' in %select{method call|property access}1 %0 before "
151151
"%select{all stored properties are initialized|"
152152
"super.init initializes self|"
153-
"self.init initializes self}2", (Identifier, bool, unsigned))
153+
"self.init initializes self}2", (DeclBaseName, bool, unsigned))
154154
ERROR(use_of_self_before_fully_init,none,
155155
"'self' used before all stored properties are initialized", ())
156156
ERROR(use_of_self_before_fully_init_protocol,none,
@@ -196,7 +196,7 @@ NOTE(initial_value_provided_in_let_decl,none,
196196
ERROR(mutating_method_called_on_immutable_value,none,
197197
"mutating %select{method|property access|subscript|operator}1 %0 may not"
198198
" be used on immutable value '%2'",
199-
(Identifier, unsigned, StringRef))
199+
(DeclBaseName, unsigned, StringRef))
200200
ERROR(immutable_value_passed_inout,none,
201201
"immutable value '%0' may not be passed inout",
202202
(StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,18 +1768,18 @@ NOTE(multiple_override_prev,none,
17681768
"%0 previously overridden here", (DeclName))
17691769

17701770
ERROR(override_unavailable,none,
1771-
"cannot override %0 which has been marked unavailable", (Identifier))
1771+
"cannot override %0 which has been marked unavailable", (DeclBaseName))
17721772
ERROR(override_unavailable_msg, none,
17731773
"cannot override %0 which has been marked unavailable: %1",
1774-
(Identifier, StringRef))
1774+
(DeclBaseName, StringRef))
17751775

17761776
ERROR(override_less_available,none,
17771777
"overriding %0 must be as available as declaration it overrides",
1778-
(Identifier))
1778+
(DeclBaseName))
17791779

17801780
ERROR(override_accessor_less_available,none,
17811781
"overriding %0 for %1 must be as available as declaration it overrides",
1782-
(DescriptiveDeclKind, Identifier))
1782+
(DescriptiveDeclKind, DeclBaseName))
17831783

17841784
ERROR(override_let_property,none,
17851785
"cannot override immutable 'let' property %0 with the getter of a 'var'",
@@ -2083,7 +2083,7 @@ ERROR(property_behavior_protocol_no_initStorage,none,
20832083
(Type, Type))
20842084
ERROR(property_behavior_unknown_requirement,none,
20852085
"property behavior protocol %0 has non-behavior requirement %1",
2086-
(Identifier, Identifier))
2086+
(Identifier, DeclBaseName))
20872087
NOTE(property_behavior_unknown_requirement_here,none,
20882088
"declared here", ())
20892089
NOTE(self_conformance_required_by_property_behavior,none,
@@ -2603,7 +2603,7 @@ NOTE(add_self_to_type,none,
26032603

26042604
WARNING(warn_unqualified_access,none,
26052605
"use of %0 treated as a reference to %1 in %2 %3",
2606-
(Identifier, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
2606+
(DeclBaseName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
26072607
NOTE(fix_unqualified_access_member,none,
26082608
"use 'self.' to silence this warning", ())
26092609
NOTE(fix_unqualified_access_top_level,none,
@@ -3571,12 +3571,12 @@ ERROR(fixed_layout_attr_on_internal_type,
35713571
none, "'@_fixed_layout' attribute can only be applied to '@_versioned' "
35723572
"or public declarations, but %0 is "
35733573
"%select{private|fileprivate|internal|%error|%error}1",
3574-
(Identifier, Accessibility))
3574+
(DeclBaseName, Accessibility))
35753575

35763576
ERROR(versioned_attr_with_explicit_accessibility,
35773577
none, "'@_versioned' attribute can only be applied to internal "
35783578
"declarations, but %0 is %select{private|fileprivate|%error|public|open}1",
3579-
(Identifier, Accessibility))
3579+
(DeclBaseName, Accessibility))
35803580

35813581
ERROR(versioned_attr_in_protocol,none,
35823582
"'@_versioned' attribute cannot be used in protocols", ())
@@ -3621,7 +3621,7 @@ ERROR(inlineable_stored_property,
36213621
ERROR(inlineable_decl_not_public,
36223622
none, "'@_inlineable' attribute can only be applied to public declarations, "
36233623
"but %0 is %select{private|fileprivate|internal|%error|%error}1",
3624-
(Identifier, Accessibility))
3624+
(DeclBaseName, Accessibility))
36253625

36263626
//------------------------------------------------------------------------------
36273627
// @_specialize diagnostics

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,8 @@ namespace {
13461346
// If this is a simple property access, then we must have a conflict.
13471347
if (subscripts.isNull()) {
13481348
assert(isa<VarDecl>(decl));
1349-
SGF.SGM.diagnose(loc1, diag::writeback_overlap_property, decl->getBaseName())
1349+
SGF.SGM.diagnose(loc1, diag::writeback_overlap_property,
1350+
decl->getBaseName().getIdentifier())
13501351
.highlight(loc1.getSourceRange());
13511352
SGF.SGM.diagnose(loc2, diag::writebackoverlap_note)
13521353
.highlight(loc2.getSourceRange());

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ static void diagnoseExclusivityViolation(const AccessedStorage &Storage,
501501
auto D = diagnose(Ctx, AccessForMainDiagnostic->getLoc().getSourceLoc(),
502502
DiagnosticID,
503503
VD->getDescriptiveKind(),
504-
VD->getBaseName(),
504+
VD->getBaseName().getIdentifier(),
505505
AccessKindForMain);
506506
D.highlight(rangeForMain);
507507
tryFixItWithCallToCollectionSwapAt(PriorAccess, NewAccess,

lib/Sema/CSDiag.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,14 +2375,14 @@ diagnoseTypeMemberOnInstanceLookup(Type baseObjTy,
23752375
// Give a customized message if we're accessing a member type
23762376
// of a protocol -- otherwise a diagnostic talking about
23772377
// static members doesn't make a whole lot of sense
2378-
if (isa<TypeAliasDecl>(member)) {
2378+
if (auto TAD = dyn_cast<TypeAliasDecl>(member)) {
23792379
Diag.emplace(diagnose(loc,
23802380
diag::typealias_outside_of_protocol,
2381-
memberName.getBaseName()));
2382-
} else if (isa<AssociatedTypeDecl>(member)) {
2381+
TAD->getName()));
2382+
} else if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
23832383
Diag.emplace(diagnose(loc,
23842384
diag::assoc_type_outside_of_protocol,
2385-
memberName.getBaseName()));
2385+
ATD->getName()));
23862386
} else {
23872387
Diag.emplace(diagnose(loc,
23882388
diag::could_not_use_type_member_on_protocol_metatype,
@@ -7876,15 +7876,15 @@ bool FailureDiagnosis::diagnoseMemberFailures(
78767876

78777877
if (auto *DRE = dyn_cast<DeclRefExpr>(baseExpr)) {
78787878
diagnose(baseExpr->getLoc(), diag::did_not_call_function,
7879-
DRE->getDecl()->getName())
7879+
DRE->getDecl()->getBaseName().getIdentifier())
78807880
.fixItInsertAfter(insertLoc, "()");
78817881
return true;
78827882
}
78837883

78847884
if (auto *DSCE = dyn_cast<DotSyntaxCallExpr>(baseExpr))
78857885
if (auto *DRE = dyn_cast<DeclRefExpr>(DSCE->getFn())) {
78867886
diagnose(baseExpr->getLoc(), diag::did_not_call_method,
7887-
DRE->getDecl()->getName())
7887+
DRE->getDecl()->getBaseName().getIdentifier())
78887888
.fixItInsertAfter(insertLoc, "()");
78897889
return true;
78907890
}
@@ -8728,8 +8728,8 @@ void FailureDiagnosis::diagnoseUnboundArchetype(ArchetypeType *archetype,
87288728
return;
87298729

87308730
auto decl = resolved.getDecl();
8731-
if (isa<FuncDecl>(decl)) {
8732-
auto name = decl->getBaseName();
8731+
if (auto FD = dyn_cast<FuncDecl>(decl)) {
8732+
auto name = FD->getName();
87338733
auto diagID = name.isOperator() ? diag::note_call_to_operator
87348734
: diag::note_call_to_func;
87358735
tc.diagnose(decl, diagID, name);
@@ -8742,8 +8742,8 @@ void FailureDiagnosis::diagnoseUnboundArchetype(ArchetypeType *archetype,
87428742
return;
87438743
}
87448744

8745-
if (isa<ParamDecl>(decl)) {
8746-
tc.diagnose(decl, diag::note_init_parameter, decl->getBaseName());
8745+
if (auto PD = dyn_cast<ParamDecl>(decl)) {
8746+
tc.diagnose(decl, diag::note_init_parameter, PD->getName());
87478747
return;
87488748
}
87498749

lib/Sema/MiscDiagnostics.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
469469
return;
470470

471471
TC.diagnose(DRE->getStartLoc(), diag::invalid_noescape_use,
472-
DRE->getDecl()->getBaseName(),
472+
cast<VarDecl>(DRE->getDecl())->getName(),
473473
isa<ParamDecl>(DRE->getDecl()));
474474

475475
// If we're a parameter, emit a helpful fixit to add @escaping
@@ -483,7 +483,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
483483
} else if (isAutoClosure)
484484
// TODO: add in a fixit for autoclosure
485485
TC.diagnose(DRE->getDecl()->getLoc(), diag::noescape_autoclosure,
486-
DRE->getDecl()->getBaseName());
486+
paramDecl->getName());
487487
}
488488

489489
// Swift 3 mode produces a warning + Fix-It for the missing ".self"
@@ -668,7 +668,7 @@ static void diagSyntacticUseRestrictions(TypeChecker &TC, const Expr *E,
668668
if (TC.getDeclTypeCheckingSemantics(DRE->getDecl())
669669
!= DeclTypeCheckingSemantics::Normal) {
670670
TC.diagnose(DRE->getLoc(), diag::unsupported_special_decl_ref,
671-
DRE->getDecl()->getBaseName());
671+
DRE->getDecl()->getBaseName().getIdentifier());
672672
}
673673
}
674674

@@ -1443,7 +1443,7 @@ static void diagnoseImplicitSelfUseInClosure(TypeChecker &TC, const Expr *E,
14431443
if (isImplicitSelfUse(MRE->getBase())) {
14441444
TC.diagnose(MRE->getLoc(),
14451445
diag::property_use_in_closure_without_explicit_self,
1446-
MRE->getMember().getDecl()->getBaseName())
1446+
MRE->getMember().getDecl()->getBaseName().getIdentifier())
14471447
.fixItInsert(MRE->getLoc(), "self.");
14481448
return { false, E };
14491449
}
@@ -1455,7 +1455,7 @@ static void diagnoseImplicitSelfUseInClosure(TypeChecker &TC, const Expr *E,
14551455
auto MethodExpr = cast<DeclRefExpr>(DSCE->getFn());
14561456
TC.diagnose(DSCE->getLoc(),
14571457
diag::method_call_in_closure_without_explicit_self,
1458-
MethodExpr->getDecl()->getBaseName())
1458+
MethodExpr->getDecl()->getBaseName().getIdentifier())
14591459
.fixItInsert(DSCE->getLoc(), "self.");
14601460
return { false, E };
14611461
}

lib/Sema/TypeCheckCaptures.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class FindCapturedVars : public ASTWalker {
207207

208208
TC.diagnose(Loc, isDecl ? diag::decl_closure_noescape_use
209209
: diag::closure_noescape_use,
210-
VD->getBaseName());
210+
VD->getBaseName().getIdentifier());
211211

212212
// If we're a parameter, emit a helpful fixit to add @escaping
213213
auto paramDecl = dyn_cast<ParamDecl>(VD);
@@ -221,7 +221,7 @@ class FindCapturedVars : public ASTWalker {
221221
} else if (isAutoClosure) {
222222
// TODO: add in a fixit for autoclosure
223223
TC.diagnose(VD->getLoc(), diag::noescape_autoclosure,
224-
VD->getBaseName());
224+
paramDecl->getName());
225225
}
226226
}
227227
}
@@ -259,7 +259,7 @@ class FindCapturedVars : public ASTWalker {
259259
if (DC->isLocalContext()) {
260260
TC.diagnose(DRE->getLoc(), diag::capture_across_type_decl,
261261
NTD->getDescriptiveKind(),
262-
D->getBaseName());
262+
D->getBaseName().getIdentifier());
263263

264264
TC.diagnose(NTD->getLoc(), diag::type_declared_here);
265265

@@ -326,18 +326,18 @@ class FindCapturedVars : public ASTWalker {
326326
if (Diagnosed.insert(capturedDecl).second) {
327327
if (capturedDecl == DRE->getDecl()) {
328328
TC.diagnose(DRE->getLoc(), diag::capture_before_declaration,
329-
capturedDecl->getBaseName());
329+
capturedDecl->getBaseName().getIdentifier());
330330
} else {
331331
TC.diagnose(DRE->getLoc(),
332332
diag::transitive_capture_before_declaration,
333-
DRE->getDecl()->getBaseName(),
334-
capturedDecl->getBaseName());
333+
DRE->getDecl()->getBaseName().getIdentifier(),
334+
capturedDecl->getBaseName().getIdentifier());
335335
ValueDecl *prevDecl = capturedDecl;
336336
for (auto path : reversed(capturePath)) {
337337
TC.diagnose(path->getLoc(),
338338
diag::transitive_capture_through_here,
339339
path->getName(),
340-
prevDecl->getBaseName());
340+
prevDecl->getBaseName().getIdentifier());
341341
prevDecl = path;
342342
}
343343
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,8 @@ resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE, DeclContext *DC) {
552552
// Diagnose uses of operators that found no matching candidates.
553553
if (ResultValues.empty()) {
554554
assert(UDRE->getRefKind() != DeclRefKind::Ordinary);
555-
diagnose(Loc, diag::use_nonmatching_operator, Name.getBaseName(),
555+
diagnose(Loc, diag::use_nonmatching_operator,
556+
Name.getBaseName().getIdentifier(),
556557
UDRE->getRefKind() == DeclRefKind::BinaryOperator ? 0 :
557558
UDRE->getRefKind() == DeclRefKind::PrefixOperator ? 1 : 2);
558559
return new (Context) ErrorExpr(UDRE->getSourceRange());

lib/Sema/TypeCheckDecl.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6339,7 +6339,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63396339
// Make sure that the overriding property doesn't have storage.
63406340
if (overrideASD->hasStorage() && !overrideASD->hasObservers()) {
63416341
TC.diagnose(overrideASD, diag::override_with_stored_property,
6342-
overrideASD->getBaseName());
6342+
overrideASD->getBaseName().getIdentifier());
63436343
TC.diagnose(baseASD, diag::property_override_here);
63446344
return true;
63456345
}
@@ -6354,7 +6354,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63546354
}
63556355
if (overrideASD->hasObservers() && !baseIsSettable) {
63566356
TC.diagnose(overrideASD, diag::observing_readonly_property,
6357-
overrideASD->getBaseName());
6357+
overrideASD->getBaseName().getIdentifier());
63586358
TC.diagnose(baseASD, diag::property_override_here);
63596359
return true;
63606360
}
@@ -6364,7 +6364,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63646364
// setter but override the getter, and that would be surprising at best.
63656365
if (baseIsSettable && !override->isSettable(override->getDeclContext())) {
63666366
TC.diagnose(overrideASD, diag::override_mutable_with_readonly_property,
6367-
overrideASD->getBaseName());
6367+
overrideASD->getBaseName().getIdentifier());
63686368
TC.diagnose(baseASD, diag::property_override_here);
63696369
return true;
63706370
}
@@ -6373,11 +6373,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63736373
// Make sure a 'let' property is only overridden by 'let' properties. A
63746374
// let property provides more guarantees than the getter of a 'var'
63756375
// property.
6376-
if (isa<VarDecl>(baseASD) && cast<VarDecl>(baseASD)->isLet()) {
6377-
TC.diagnose(overrideASD, diag::override_let_property,
6378-
overrideASD->getBaseName());
6379-
TC.diagnose(baseASD, diag::property_override_here);
6380-
return true;
6376+
if (auto VD = dyn_cast<VarDecl>(baseASD)) {
6377+
if (VD->isLet()) {
6378+
TC.diagnose(overrideASD, diag::override_let_property,
6379+
VD->getName());
6380+
TC.diagnose(baseASD, diag::property_override_here);
6381+
return true;
6382+
}
63816383
}
63826384
}
63836385

0 commit comments

Comments
 (0)