Skip to content

Commit faa1720

Browse files
committed
[Diagnostics] Adjustments for DeclBaseName
Adjust the definition of some diagnostics that are already called with DeclBaseNames so that the implicit conversion from DeclBaseName to Identifier is no longer needed. Adjust the call side of diagnostics which don't have to deal with special names to pass an Identifier to the diagnostic.
1 parent ae947cb commit faa1720

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
@@ -145,7 +145,7 @@ ERROR(self_use_before_fully_init,none,
145145
"use of 'self' in %select{method call|property access}1 %0 before "
146146
"%select{all stored properties are initialized|"
147147
"super.init initializes self|"
148-
"self.init initializes self}2", (Identifier, bool, unsigned))
148+
"self.init initializes self}2", (DeclBaseName, bool, unsigned))
149149
ERROR(use_of_self_before_fully_init,none,
150150
"'self' used before all stored properties are initialized", ())
151151
ERROR(use_of_self_before_fully_init_protocol,none,
@@ -191,7 +191,7 @@ NOTE(initial_value_provided_in_let_decl,none,
191191
ERROR(mutating_method_called_on_immutable_value,none,
192192
"mutating %select{method|property access|subscript|operator}1 %0 may not"
193193
" be used on immutable value '%2'",
194-
(Identifier, unsigned, StringRef))
194+
(DeclBaseName, unsigned, StringRef))
195195
ERROR(immutable_value_passed_inout,none,
196196
"immutable value '%0' may not be passed inout",
197197
(StringRef))

include/swift/AST/DiagnosticsSema.def

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

17781778
ERROR(override_unavailable,none,
1779-
"cannot override %0 which has been marked unavailable", (Identifier))
1779+
"cannot override %0 which has been marked unavailable", (DeclBaseName))
17801780
ERROR(override_unavailable_msg, none,
17811781
"cannot override %0 which has been marked unavailable: %1",
1782-
(Identifier, StringRef))
1782+
(DeclBaseName, StringRef))
17831783

17841784
ERROR(override_less_available,none,
17851785
"overriding %0 must be as available as declaration it overrides",
1786-
(Identifier))
1786+
(DeclBaseName))
17871787

17881788
ERROR(override_accessor_less_available,none,
17891789
"overriding %0 for %1 must be as available as declaration it overrides",
1790-
(DescriptiveDeclKind, Identifier))
1790+
(DescriptiveDeclKind, DeclBaseName))
17911791

17921792
ERROR(override_let_property,none,
17931793
"cannot override immutable 'let' property %0 with the getter of a 'var'",
@@ -2089,7 +2089,7 @@ ERROR(property_behavior_protocol_no_initStorage,none,
20892089
(Type, Type))
20902090
ERROR(property_behavior_unknown_requirement,none,
20912091
"property behavior protocol %0 has non-behavior requirement %1",
2092-
(Identifier, Identifier))
2092+
(Identifier, DeclBaseName))
20932093
NOTE(property_behavior_unknown_requirement_here,none,
20942094
"declared here", ())
20952095
NOTE(self_conformance_required_by_property_behavior,none,
@@ -2607,7 +2607,7 @@ NOTE(add_self_to_type,none,
26072607

26082608
WARNING(warn_unqualified_access,none,
26092609
"use of %0 treated as a reference to %1 in %2 %3",
2610-
(Identifier, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
2610+
(DeclBaseName, DescriptiveDeclKind, DescriptiveDeclKind, DeclName))
26112611
NOTE(fix_unqualified_access_member,none,
26122612
"use 'self.' to silence this warning", ())
26132613
NOTE(fix_unqualified_access_top_level,none,
@@ -3566,12 +3566,12 @@ ERROR(fixed_layout_attr_on_internal_type,
35663566
none, "'@_fixed_layout' attribute can only be applied to '@_versioned' "
35673567
"or public declarations, but %0 is "
35683568
"%select{private|fileprivate|internal|%error|%error}1",
3569-
(Identifier, Accessibility))
3569+
(DeclBaseName, Accessibility))
35703570

35713571
ERROR(versioned_attr_with_explicit_accessibility,
35723572
none, "'@_versioned' attribute can only be applied to internal "
35733573
"declarations, but %0 is %select{private|fileprivate|%error|public|open}1",
3574-
(Identifier, Accessibility))
3574+
(DeclBaseName, Accessibility))
35753575

35763576
ERROR(versioned_attr_in_protocol,none,
35773577
"'@_versioned' attribute cannot be used in protocols", ())
@@ -3616,7 +3616,7 @@ ERROR(inlineable_stored_property,
36163616
ERROR(inlineable_decl_not_public,
36173617
none, "'@_inlineable' attribute can only be applied to public declarations, "
36183618
"but %0 is %select{private|fileprivate|internal|%error|%error}1",
3619-
(Identifier, Accessibility))
3619+
(DeclBaseName, Accessibility))
36203620

36213621
//------------------------------------------------------------------------------
36223622
// @_specialize diagnostics

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,8 @@ namespace {
13521352
// If this is a simple property access, then we must have a conflict.
13531353
if (!subscripts) {
13541354
assert(isa<VarDecl>(decl));
1355-
SGF.SGM.diagnose(loc1, diag::writeback_overlap_property, decl->getBaseName())
1355+
SGF.SGM.diagnose(loc1, diag::writeback_overlap_property,
1356+
decl->getBaseName().getIdentifier())
13561357
.highlight(loc1.getSourceRange());
13571358
SGF.SGM.diagnose(loc2, diag::writebackoverlap_note)
13581359
.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
@@ -2376,14 +2376,14 @@ diagnoseTypeMemberOnInstanceLookup(Type baseObjTy,
23762376
// Give a customized message if we're accessing a member type
23772377
// of a protocol -- otherwise a diagnostic talking about
23782378
// static members doesn't make a whole lot of sense
2379-
if (isa<TypeAliasDecl>(member)) {
2379+
if (auto TAD = dyn_cast<TypeAliasDecl>(member)) {
23802380
Diag.emplace(diagnose(loc,
23812381
diag::typealias_outside_of_protocol,
2382-
memberName.getBaseName()));
2383-
} else if (isa<AssociatedTypeDecl>(member)) {
2382+
TAD->getName()));
2383+
} else if (auto ATD = dyn_cast<AssociatedTypeDecl>(member)) {
23842384
Diag.emplace(diagnose(loc,
23852385
diag::assoc_type_outside_of_protocol,
2386-
memberName.getBaseName()));
2386+
ATD->getName()));
23872387
} else {
23882388
Diag.emplace(diagnose(loc,
23892389
diag::could_not_use_type_member_on_protocol_metatype,
@@ -7743,15 +7743,15 @@ bool FailureDiagnosis::diagnoseMemberFailures(
77437743

77447744
if (auto *DRE = dyn_cast<DeclRefExpr>(baseExpr)) {
77457745
diagnose(baseExpr->getLoc(), diag::did_not_call_function,
7746-
DRE->getDecl()->getName())
7746+
DRE->getDecl()->getBaseName().getIdentifier())
77477747
.fixItInsertAfter(insertLoc, "()");
77487748
return true;
77497749
}
77507750

77517751
if (auto *DSCE = dyn_cast<DotSyntaxCallExpr>(baseExpr))
77527752
if (auto *DRE = dyn_cast<DeclRefExpr>(DSCE->getFn())) {
77537753
diagnose(baseExpr->getLoc(), diag::did_not_call_method,
7754-
DRE->getDecl()->getName())
7754+
DRE->getDecl()->getBaseName().getIdentifier())
77557755
.fixItInsertAfter(insertLoc, "()");
77567756
return true;
77577757
}
@@ -8595,8 +8595,8 @@ void FailureDiagnosis::diagnoseUnboundArchetype(ArchetypeType *archetype,
85958595
return;
85968596

85978597
auto decl = resolved.getDecl();
8598-
if (isa<FuncDecl>(decl)) {
8599-
auto name = decl->getBaseName();
8598+
if (auto FD = dyn_cast<FuncDecl>(decl)) {
8599+
auto name = FD->getName();
86008600
auto diagID = name.isOperator() ? diag::note_call_to_operator
86018601
: diag::note_call_to_func;
86028602
tc.diagnose(decl, diagID, name);
@@ -8609,8 +8609,8 @@ void FailureDiagnosis::diagnoseUnboundArchetype(ArchetypeType *archetype,
86098609
return;
86108610
}
86118611

8612-
if (isa<ParamDecl>(decl)) {
8613-
tc.diagnose(decl, diag::note_init_parameter, decl->getBaseName());
8612+
if (auto PD = dyn_cast<ParamDecl>(decl)) {
8613+
tc.diagnose(decl, diag::note_init_parameter, PD->getName());
86148614
return;
86158615
}
86168616

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
@@ -6341,7 +6341,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63416341
// Make sure that the overriding property doesn't have storage.
63426342
if (overrideASD->hasStorage() && !overrideASD->hasObservers()) {
63436343
TC.diagnose(overrideASD, diag::override_with_stored_property,
6344-
overrideASD->getBaseName());
6344+
overrideASD->getBaseName().getIdentifier());
63456345
TC.diagnose(baseASD, diag::property_override_here);
63466346
return true;
63476347
}
@@ -6356,7 +6356,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63566356
}
63576357
if (overrideASD->hasObservers() && !baseIsSettable) {
63586358
TC.diagnose(overrideASD, diag::observing_readonly_property,
6359-
overrideASD->getBaseName());
6359+
overrideASD->getBaseName().getIdentifier());
63606360
TC.diagnose(baseASD, diag::property_override_here);
63616361
return true;
63626362
}
@@ -6366,7 +6366,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63666366
// setter but override the getter, and that would be surprising at best.
63676367
if (baseIsSettable && !override->isSettable(override->getDeclContext())) {
63686368
TC.diagnose(overrideASD, diag::override_mutable_with_readonly_property,
6369-
overrideASD->getBaseName());
6369+
overrideASD->getBaseName().getIdentifier());
63706370
TC.diagnose(baseASD, diag::property_override_here);
63716371
return true;
63726372
}
@@ -6375,11 +6375,13 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
63756375
// Make sure a 'let' property is only overridden by 'let' properties. A
63766376
// let property provides more guarantees than the getter of a 'var'
63776377
// property.
6378-
if (isa<VarDecl>(baseASD) && cast<VarDecl>(baseASD)->isLet()) {
6379-
TC.diagnose(overrideASD, diag::override_let_property,
6380-
overrideASD->getBaseName());
6381-
TC.diagnose(baseASD, diag::property_override_here);
6382-
return true;
6378+
if (auto VD = dyn_cast<VarDecl>(baseASD)) {
6379+
if (VD->isLet()) {
6380+
TC.diagnose(overrideASD, diag::override_let_property,
6381+
VD->getName());
6382+
TC.diagnose(baseASD, diag::property_override_here);
6383+
return true;
6384+
}
63836385
}
63846386
}
63856387

0 commit comments

Comments
 (0)