Skip to content

Commit 1318bf5

Browse files
committed
[NFC] Begin adopting new diagnostics features
1 parent 2ab1e05 commit 1318bf5

File tree

5 files changed

+67
-85
lines changed

5 files changed

+67
-85
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1668,14 +1668,14 @@ ERROR(attr_objc_implementation_must_be_unconditional,none,
16681668
"only unconditional extensions can implement an Objective-C '@interface'",
16691669
())
16701670
ERROR(attr_objc_implementation_must_extend_class,none,
1671-
"cannot mark extension of %0 %1 with '@_objcImplementation'; it is not "
1671+
"cannot mark extension of %kind0 with '@_objcImplementation'; it is not "
16721672
"an imported Objective-C class",
1673-
(DescriptiveDeclKind, ValueDecl *))
1673+
(ValueDecl *))
16741674
ERROR(attr_objc_implementation_must_be_imported,none,
1675-
"'@_objcImplementation' cannot be used to extend %0 %1 because it was "
1675+
"'@_objcImplementation' cannot be used to extend %kind0 because it was "
16761676
"defined by a Swift 'class' declaration, not an imported Objective-C "
16771677
"'@interface' declaration",
1678-
(DescriptiveDeclKind, ValueDecl *))
1678+
(ValueDecl *))
16791679
ERROR(attr_objc_implementation_category_not_found,none,
16801680
"could not find category %0 on Objective-C class %1; make sure your "
16811681
"umbrella or bridging header imports the header that declares it",
@@ -1702,29 +1702,28 @@ NOTE(fixit_add_final_for_objc_implementation,none,
17021702
(DescriptiveDeclKind))
17031703

17041704
ERROR(objc_implementation_wrong_category,none,
1705-
"%0 %1 should be implemented in extension for "
1706-
"%select{main class interface|category %2}2, not "
1707-
"%select{main class interface|category %3}3",
1708-
(DescriptiveDeclKind, ValueDecl *, Identifier, Identifier))
1705+
"%kind0 should be implemented in extension for "
1706+
"%select{main class interface|category %1}1, not "
1707+
"%select{main class interface|category %2}2",
1708+
(ValueDecl *, Identifier, Identifier))
17091709

17101710
ERROR(objc_implementation_wrong_decl_kind,none,
1711-
"%0 %1 does not match the %2 declared by the header",
1712-
(DescriptiveDeclKind, ValueDecl *, DescriptiveDeclKind))
1711+
"%kind0 does not match the %1 declared by the header",
1712+
(ValueDecl *, DescriptiveDeclKind))
17131713

17141714
ERROR(objc_implementation_must_be_settable,none,
1715-
"%0 %1 should be settable to match the settable %2 declared by the "
1715+
"%kind0 should be settable to match the settable %1 declared by the "
17161716
"header",
1717-
(DescriptiveDeclKind, ValueDecl *, DescriptiveDeclKind))
1717+
(ValueDecl *, DescriptiveDeclKind))
17181718

17191719
ERROR(objc_implementation_type_mismatch,none,
1720-
"%0 %1 of type %2 does not match type %3 declared by the "
1721-
"header",
1722-
(DescriptiveDeclKind, ValueDecl *, Type, Type))
1720+
"%kind0 of type %1 does not match type %2 declared by the header",
1721+
(ValueDecl *, Type, Type))
17231722

17241723
ERROR(objc_implementation_required_attr_mismatch,none,
1725-
"%0 %1 %select{should not|should}2 be 'required' to match %0 declared by "
1726-
"the header",
1727-
(DescriptiveDeclKind, ValueDecl *, bool))
1724+
"%kind0 %select{should not|should}2 be 'required' to match %1 declared "
1725+
"by the header",
1726+
(ValueDecl *, DescriptiveDeclKind, bool))
17281727

17291728
ERROR(objc_implementation_candidate_has_error_convention,none,
17301729
"%0 %1 does not match the declaration in the header because it throws an "
@@ -1770,8 +1769,8 @@ ERROR(objc_implementation_mismatched_error_convention_other,none,
17701769
(DescriptiveDeclKind, ValueDecl *))
17711770

17721771
ERROR(objc_implementation_wrong_objc_name,none,
1773-
"selector %0 for %1 %2 not found in header; did you mean %3?",
1774-
(ObjCSelector, DescriptiveDeclKind, ValueDecl *, ObjCSelector))
1772+
"selector %0 for %kind1 not found in header; did you mean %2?",
1773+
(ObjCSelector, ValueDecl *, ObjCSelector))
17751774

17761775
ERROR(objc_implementation_wrong_swift_name,none,
17771776
"selector %0 used in header by an %1 with a different name; did you "
@@ -1780,30 +1779,30 @@ ERROR(objc_implementation_wrong_swift_name,none,
17801779

17811780
ERROR(objc_implementation_missing_impl,none,
17821781
"extension for %select{main class interface|category %0}0 should "
1783-
"provide implementation for %1 %2",
1784-
(Identifier, DescriptiveDeclKind, ValueDecl *))
1782+
"provide implementation for %kind1",
1783+
(Identifier, ValueDecl *))
17851784

17861785
ERROR(objc_implementation_class_or_instance_mismatch,none,
1787-
"%0 %1 does not match %2 declared in header",
1788-
(DescriptiveDeclKind, ValueDecl *, DescriptiveDeclKind))
1786+
"%kind0 does not match %1 declared in header",
1787+
(ValueDecl *, DescriptiveDeclKind))
17891788

17901789
ERROR(objc_implementation_multiple_matching_candidates,none,
1791-
"found multiple implementations that could match %0 %1 with selector %2",
1792-
(DescriptiveDeclKind, ValueDecl *, ObjCSelector))
1790+
"found multiple implementations that could match %kind0 with selector %1",
1791+
(ValueDecl *, ObjCSelector))
17931792
NOTE(objc_implementation_candidate_impl_here,none,
1794-
"%0 %1 is a potential match%select{|; insert '@objc(%3)' to use it}2",
1795-
(DescriptiveDeclKind, ValueDecl *, bool, StringRef))
1793+
"%kind0 is a potential match%select{|; insert '@objc(%2)' to use it}1",
1794+
(ValueDecl *, bool, StringRef))
17961795
NOTE(objc_implementation_requirement_here,none,
1797-
"%0 %1 declared in header here",
1798-
(DescriptiveDeclKind, ValueDecl *))
1796+
"%kind0 declared in header here",
1797+
(ValueDecl *))
17991798

18001799
ERROR(objc_implementation_multiple_matching_requirements,none,
1801-
"%0 %1 could match several different members declared in the header",
1802-
(DescriptiveDeclKind, ValueDecl *))
1800+
"%kind0 could match several different members declared in the header",
1801+
(ValueDecl *))
18031802
NOTE(objc_implementation_one_matched_requirement,none,
1804-
"%0 %1 (with selector %2) is a potential match%select{|; insert "
1805-
"'@objc(%4)' to use it}3",
1806-
(DescriptiveDeclKind, ValueDecl *, ObjCSelector, bool, StringRef))
1803+
"%kind0 (with selector %1) is a potential match%select{|; insert "
1804+
"'@objc(%3)' to use it}2",
1805+
(ValueDecl *, ObjCSelector, bool, StringRef))
18071806

18081807
ERROR(cdecl_not_at_top_level,none,
18091808
"@_cdecl can only be applied to global functions", ())
@@ -1830,19 +1829,19 @@ ERROR(expose_invalid_name_pattern_init,none,
18301829
"invalid declaration name '%0' specified in an @_expose attribute; "
18311830
"exposed initializer name must start with 'init'", (StringRef))
18321831
ERROR(expose_unsupported_objc_decl_to_cxx,none,
1833-
"@objc %0 %1 can not yet be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1832+
"@objc %kind0 can not yet be exposed to C++", (ValueDecl *))
18341833
ERROR(expose_unsupported_async_decl_to_cxx,none,
1835-
"async %0 %1 can not be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1834+
"async %kind0 can not be exposed to C++", (ValueDecl *))
18361835
ERROR(expose_unsupported_actor_isolated_to_cxx,none,
1837-
"actor-isolated %0 %1 can not be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1836+
"actor-isolated %kind0 can not be exposed to C++", (ValueDecl *))
18381837
ERROR(expose_unsupported_client_emission_to_cxx,none,
1839-
"%0 %1 can not be exposed to C++ as it requires code to be emitted into client", (DescriptiveDeclKind, ValueDecl *))
1838+
"%kind0 can not be exposed to C++ as it requires code to be emitted into client", (ValueDecl *))
18401839
ERROR(expose_generic_decl_to_cxx,none,
1841-
"generic %0 %1 can not yet be exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1840+
"generic %kind0 can not yet be exposed to C++", (ValueDecl *))
18421841
ERROR(expose_generic_requirement_to_cxx,none,
1843-
"generic requirements for %0 %1 can not yet be represented in C++", (DescriptiveDeclKind, ValueDecl *))
1842+
"generic requirements for %kind0 can not yet be represented in C++", (ValueDecl *))
18441843
ERROR(expose_throwing_to_cxx,none,
1845-
"%0 %1 can not yet be represented in C++ as it may throw an error", (DescriptiveDeclKind, ValueDecl *))
1844+
"%kind0 can not yet be represented in C++ as it may throw an error", (ValueDecl *))
18461845
ERROR(expose_indirect_enum_cxx,none,
18471846
"indirect enum %0 can not yet be represented in C++", (ValueDecl *))
18481847
ERROR(expose_enum_case_type_to_cxx,none,
@@ -1852,11 +1851,11 @@ ERROR(expose_enum_case_tuple_to_cxx,none,
18521851
ERROR(expose_protocol_to_cxx_unsupported,none,
18531852
"protocol %0 can not yet be represented in C++", (ValueDecl *))
18541853
ERROR(expose_move_only_to_cxx,none,
1855-
"noncopyable %0 %1 can not yet be represented in C++", (DescriptiveDeclKind, ValueDecl *))
1854+
"noncopyable %kind0 can not yet be represented in C++", (ValueDecl *))
18561855
ERROR(unexposed_other_decl_in_cxx,none,
1857-
"%0 %1 is not yet exposed to C++", (DescriptiveDeclKind, ValueDecl *))
1856+
"%kind0 is not yet exposed to C++", (ValueDecl *))
18581857
ERROR(unsupported_other_decl_in_cxx,none,
1859-
"Swift %0 %1 cannot be represented in C++", (DescriptiveDeclKind, ValueDecl *))
1858+
"Swift %kind0 cannot be represented in C++", (ValueDecl *))
18601859

18611860
ERROR(attr_methods_only,none,
18621861
"only methods can be declared %0", (DeclAttribute))

lib/AST/SwiftNameTranslation.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,19 @@ swift::cxx_translation::diagnoseRepresenationError(RepresentationError error,
298298
ValueDecl *vd) {
299299
switch (error) {
300300
case UnrepresentableObjC:
301-
return Diagnostic(diag::expose_unsupported_objc_decl_to_cxx,
302-
vd->getDescriptiveKind(), vd);
301+
return Diagnostic(diag::expose_unsupported_objc_decl_to_cxx, vd);
303302
case UnrepresentableAsync:
304-
return Diagnostic(diag::expose_unsupported_async_decl_to_cxx,
305-
vd->getDescriptiveKind(), vd);
303+
return Diagnostic(diag::expose_unsupported_async_decl_to_cxx, vd);
306304
case UnrepresentableIsolatedInActor:
307-
return Diagnostic(diag::expose_unsupported_actor_isolated_to_cxx,
308-
vd->getDescriptiveKind(), vd);
305+
return Diagnostic(diag::expose_unsupported_actor_isolated_to_cxx, vd);
309306
case UnrepresentableRequiresClientEmission:
310-
return Diagnostic(diag::expose_unsupported_client_emission_to_cxx,
311-
vd->getDescriptiveKind(), vd);
307+
return Diagnostic(diag::expose_unsupported_client_emission_to_cxx, vd);
312308
case UnrepresentableGeneric:
313-
return Diagnostic(diag::expose_generic_decl_to_cxx,
314-
vd->getDescriptiveKind(), vd);
309+
return Diagnostic(diag::expose_generic_decl_to_cxx, vd);
315310
case UnrepresentableGenericRequirements:
316-
return Diagnostic(diag::expose_generic_requirement_to_cxx,
317-
vd->getDescriptiveKind(), vd);
311+
return Diagnostic(diag::expose_generic_requirement_to_cxx, vd);
318312
case UnrepresentableThrows:
319-
return Diagnostic(diag::expose_throwing_to_cxx, vd->getDescriptiveKind(),
320-
vd);
313+
return Diagnostic(diag::expose_throwing_to_cxx, vd);
321314
case UnrepresentableIndirectEnum:
322315
return Diagnostic(diag::expose_indirect_enum_cxx, vd);
323316
case UnrepresentableEnumCaseType:
@@ -327,7 +320,6 @@ swift::cxx_translation::diagnoseRepresenationError(RepresentationError error,
327320
case UnrepresentableProtocol:
328321
return Diagnostic(diag::expose_protocol_to_cxx_unsupported, vd);
329322
case UnrepresentableMoveOnly:
330-
return Diagnostic(diag::expose_move_only_to_cxx, vd->getDescriptiveKind(),
331-
vd);
323+
return Diagnostic(diag::expose_move_only_to_cxx, vd);
332324
}
333325
}

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ class ModuleWriter {
884884
: Diagnostic(
885885
vd->isStdlibDecl() ? diag::unexposed_other_decl_in_cxx
886886
: diag::unsupported_other_decl_in_cxx,
887-
vd->getDescriptiveKind(), const_cast<ValueDecl *>(vd));
887+
const_cast<ValueDecl *>(vd));
888888
// Emit a specific unavailable message when we know why a decl can't be
889889
// exposed, or a generic message otherwise.
890890
auto diagString = M.getASTContext().Diags.diagnosticStringFor(

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,6 @@ visitObjCImplementationAttr(ObjCImplementationAttr *attr) {
14821482
if (!CD) {
14831483
diagnoseAndRemoveAttr(attr,
14841484
diag::attr_objc_implementation_must_extend_class,
1485-
ED->getExtendedNominal()->getDescriptiveKind(),
14861485
ED->getExtendedNominal());
14871486
ED->getExtendedNominal()->diagnose(diag::decl_declared_here,
14881487
ED->getExtendedNominal()->getName());
@@ -1491,7 +1490,7 @@ visitObjCImplementationAttr(ObjCImplementationAttr *attr) {
14911490

14921491
if (!CD->hasClangNode()) {
14931492
diagnoseAndRemoveAttr(attr, diag::attr_objc_implementation_must_be_imported,
1494-
CD->getDescriptiveKind(), CD);
1493+
CD);
14951494
CD->diagnose(diag::decl_declared_here, CD->getName());
14961495
return;
14971496
}

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,14 +3138,13 @@ class ObjCImplementationChecker {
31383138

31393139
// Ambiguous match (many requirements match one candidate)
31403140
diagnose(cand, diag::objc_implementation_multiple_matching_requirements,
3141-
cand->getDescriptiveKind(), cand);
3141+
cand);
31423142

31433143
bool shouldOfferFix = !candExplicitObjCName;
31443144
for (auto req : matchedRequirements.matches) {
31453145
auto diag =
31463146
diagnose(cand, diag::objc_implementation_one_matched_requirement,
3147-
req->getDescriptiveKind(), req,
3148-
*req->getObjCRuntimeName(), shouldOfferFix,
3147+
req, *req->getObjCRuntimeName(), shouldOfferFix,
31493148
req->getObjCRuntimeName()->getString(scratch));
31503149
if (shouldOfferFix) {
31513150
fixDeclarationObjCName(diag, cand, cand->getObjCRuntimeName(),
@@ -3187,14 +3186,13 @@ class ObjCImplementationChecker {
31873186
auto ext =
31883187
cast<ExtensionDecl>(reqIDC->getImplementationContext());
31893188
diagnose(ext, diag::objc_implementation_multiple_matching_candidates,
3190-
req->getDescriptiveKind(), req,
3191-
*req->getObjCRuntimeName());
3189+
req, *req->getObjCRuntimeName());
31923190

31933191
for (auto cand : cands.matches) {
31943192
bool shouldOfferFix = !unmatchedCandidates[cand];
31953193
auto diag =
31963194
diagnose(cand, diag::objc_implementation_candidate_impl_here,
3197-
cand->getDescriptiveKind(), cand, shouldOfferFix,
3195+
cand, shouldOfferFix,
31983196
req->getObjCRuntimeName()->getString(scratch));
31993197

32003198
if (shouldOfferFix) {
@@ -3204,8 +3202,7 @@ class ObjCImplementationChecker {
32043202
}
32053203
}
32063204

3207-
diagnose(req, diag::objc_implementation_requirement_here,
3208-
req->getDescriptiveKind(), req);
3205+
diagnose(req, diag::objc_implementation_requirement_here, req);
32093206
}
32103207

32113208
// Remove matched candidates and requirements from the unmatched lists.
@@ -3377,8 +3374,7 @@ class ObjCImplementationChecker {
33773374
case MatchOutcome::WrongImplicitObjCName:
33783375
case MatchOutcome::WrongExplicitObjCName: {
33793376
auto diag = diagnose(cand, diag::objc_implementation_wrong_objc_name,
3380-
*cand->getObjCRuntimeName(),
3381-
cand->getDescriptiveKind(), cand, reqObjCName);
3377+
*cand->getObjCRuntimeName(), cand, reqObjCName);
33823378
fixDeclarationObjCName(diag, cand, explicitObjCName, reqObjCName);
33833379
return;
33843380
}
@@ -3400,42 +3396,39 @@ class ObjCImplementationChecker {
34003396
case MatchOutcome::WrongStaticness: {
34013397
auto diag = diagnose(cand,
34023398
diag::objc_implementation_class_or_instance_mismatch,
3403-
cand->getDescriptiveKind(), cand,
3404-
req->getDescriptiveKind());
3399+
cand, req->getDescriptiveKind());
34053400
fixDeclarationStaticSpelling(diag, cand, getStaticSpelling(req));
34063401
return;
34073402
}
34083403

34093404
case MatchOutcome::WrongCategory:
34103405
diagnose(cand, diag::objc_implementation_wrong_category,
3411-
cand->getDescriptiveKind(), cand,
3412-
getCategoryName(req->getDeclContext()),
3406+
cand, getCategoryName(req->getDeclContext()),
34133407
getCategoryName(cand->getDeclContext()->
34143408
getImplementedObjCContext()));
34153409
return;
34163410

34173411
case MatchOutcome::WrongDeclKind:
34183412
diagnose(cand, diag::objc_implementation_wrong_decl_kind,
3419-
cand->getDescriptiveKind(), cand, req->getDescriptiveKind());
3413+
cand, req->getDescriptiveKind());
34203414
return;
34213415

34223416
case MatchOutcome::WrongType:
34233417
diagnose(cand, diag::objc_implementation_type_mismatch,
3424-
cand->getDescriptiveKind(), cand,
3425-
getMemberType(cand), getMemberType(req));
3418+
cand, getMemberType(cand), getMemberType(req));
34263419
return;
34273420

34283421
case MatchOutcome::WrongWritability:
34293422
diagnose(cand, diag::objc_implementation_must_be_settable,
3430-
cand->getDescriptiveKind(), cand, req->getDescriptiveKind());
3423+
cand, req->getDescriptiveKind());
34313424
return;
34323425

34333426
case MatchOutcome::WrongRequiredAttr: {
34343427
bool shouldBeRequired = cast<ConstructorDecl>(req)->isRequired();
34353428

34363429
auto diag =
34373430
diagnose(cand, diag::objc_implementation_required_attr_mismatch,
3438-
cand->getDescriptiveKind(), cand, shouldBeRequired);
3431+
cand, req->getDescriptiveKind(), shouldBeRequired);
34393432

34403433
if (shouldBeRequired)
34413434
diag.fixItInsert(cand->getAttributeInsertionLoc(/*forModifier=*/true),
@@ -3522,8 +3515,7 @@ class ObjCImplementationChecker {
35223515
->getImplementationContext();
35233516

35243517
diagnose(ext->getDecl(), diag::objc_implementation_missing_impl,
3525-
getCategoryName(req->getDeclContext()),
3526-
req->getDescriptiveKind(), req);
3518+
getCategoryName(req->getDeclContext()), req);
35273519

35283520
// FIXME: Should give fix-it to add stub implementation
35293521
}

0 commit comments

Comments
 (0)