@@ -1446,6 +1446,16 @@ void TypeChecker::diagnoseDuplicateCaptureVars(CaptureListExpr *expr) {
1446
1446
diagnoseDuplicateDecls (captureListVars);
1447
1447
}
1448
1448
1449
+ template <typename ...DiagIDAndArgs> InFlightDiagnostic
1450
+ diagnoseForAccessNote (DeclAttribute *attr, ValueDecl *VD,
1451
+ DiagIDAndArgs... idAndArgs) {
1452
+ ASTContext &ctx = VD->getASTContext ();
1453
+ if (attr->getLocation ().isValid ())
1454
+ return ctx.Diags .diagnose (attr->getLocation (), idAndArgs...);
1455
+ else
1456
+ return ctx.Diags .diagnose (VD, idAndArgs...);
1457
+ }
1458
+
1449
1459
template <typename Attr>
1450
1460
static void addOrRemoveAttr (ValueDecl *VD, const AccessNotes ¬es,
1451
1461
Optional<bool > expected,
@@ -1459,20 +1469,10 @@ static void addOrRemoveAttr(ValueDecl *VD, const AccessNotes ¬es,
1459
1469
[&](Diag<StringRef, bool , StringRef, DescriptiveDeclKind> diagID,
1460
1470
Diag<bool > fixitID) -> InFlightDiagnostic {
1461
1471
bool isModifier = attr->isDeclModifier ();
1462
- Diagnostic warning (diagID, notes.reason , isModifier, attr->getAttrName (),
1463
- VD->getDescriptiveKind ());
1464
- Diagnostic note (fixitID, isModifier);
1465
1472
1466
- ASTContext &ctx = VD->getASTContext ();
1467
-
1468
- if (attr->getLocation ().isValid ()) {
1469
- ctx.Diags .diagnose (attr->getLocation (), warning);
1470
- return ctx.Diags .diagnose (attr->getLocation (), note);
1471
- }
1472
- else {
1473
- ctx.Diags .diagnose (VD, warning);
1474
- return ctx.Diags .diagnose (VD->getAttributeInsertionLoc (isModifier), note);
1475
- }
1473
+ diagnoseForAccessNote (attr, VD, diagID, notes.reason , isModifier,
1474
+ attr->getAttrName (), VD->getDescriptiveKind ());
1475
+ return diagnoseForAccessNote (attr, VD, fixitID, isModifier);
1476
1476
};
1477
1477
1478
1478
if (*expected) {
@@ -1513,20 +1513,19 @@ static void applyAccessNote(ValueDecl *VD, const AccessNote ¬e,
1513
1513
1514
1514
if (!attr->hasName ()) {
1515
1515
attr->setName (*note.ObjCName , true );
1516
- ctx. Diags . diagnose (attr-> getLocation () ,
1517
- diag::attr_objc_name_changed_by_access_note,
1518
- notes.reason , VD->getDescriptiveKind (),
1519
- *note.ObjCName );
1516
+ diagnoseForAccessNote (attr, VD ,
1517
+ diag::attr_objc_name_changed_by_access_note,
1518
+ notes.reason , VD->getDescriptiveKind (),
1519
+ *note.ObjCName );
1520
1520
1521
1521
SmallString<64 > newNameString;
1522
1522
llvm::raw_svector_ostream os (newNameString);
1523
1523
os << " (" ;
1524
1524
os << *note.ObjCName ;
1525
1525
os << " )" ;
1526
1526
1527
- auto note =
1528
- ctx.Diags .diagnose (attr->getLocation (),
1529
- diag::fixit_attr_objc_name_changed_by_access_note);
1527
+ auto note = diagnoseForAccessNote (attr, VD,
1528
+ diag::fixit_attr_objc_name_changed_by_access_note);
1530
1529
1531
1530
if (attr->getLParenLoc ().isValid ())
1532
1531
note.fixItReplace ({ attr->getLParenLoc (), attr->getRParenLoc () },
@@ -1537,6 +1536,7 @@ static void applyAccessNote(ValueDecl *VD, const AccessNote ¬e,
1537
1536
else if (attr->getName () != *note.ObjCName ) {
1538
1537
// TODO: diagnose conflict between explicit name in code and explicit
1539
1538
// name in access note
1539
+ llvm::report_fatal_error (" conflict between name in code and name in access note" );
1540
1540
}
1541
1541
}
1542
1542
}
0 commit comments