Skip to content

Commit 4743d9f

Browse files
committed
Diagnose @objc(selector) access note conflicts
1 parent d51a3be commit 4743d9f

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5670,6 +5670,10 @@ WARNING(attr_objc_name_changed_by_access_note, none,
56705670
WARNING(fixit_attr_objc_name_changed_by_access_note, none,
56715671
"change '@objc' name in source code explicitly to silence this warning",
56725672
())
5673+
WARNING(attr_objc_name_conflicts_with_access_note, none,
5674+
"access note for %0 changes the '@objc' name of this %1 to %2, but "
5675+
"source code specifies %3; the access note will be ignored",
5676+
(StringRef, DescriptiveDeclKind, ObjCSelector, ObjCSelector))
56735677

56745678
#define UNDEFINE_DIAGNOSTIC_MACROS
56755679
#include "DefineDiagnosticMacros.h"

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,9 +1534,10 @@ static void applyAccessNote(ValueDecl *VD, const AccessNote &note,
15341534
note.fixItInsertAfter(attr->getLocation(), newNameString);
15351535
}
15361536
else if (attr->getName() != *note.ObjCName) {
1537-
// TODO: diagnose conflict between explicit name in code and explicit
1538-
// name in access note
1539-
llvm::report_fatal_error("conflict between name in code and name in access note");
1537+
diagnoseForAccessNote(attr, VD,
1538+
diag::attr_objc_name_conflicts_with_access_note,
1539+
notes.reason, VD->getDescriptiveKind(),
1540+
*note.ObjCName, *attr->getName());
15401541
}
15411542
}
15421543
}

test/SILGen/Inputs/objc_access_notes.accessnotes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ Notes:
5353
ObjC: true
5454
- Name: 'Wotsit.plain()'
5555
ObjC: true
56+
ObjCName: 'fancy'

test/SILGen/objc_access_notes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,9 @@ class Wotsit<T> : Gizmo {
456456
// CHECK-NEXT: destroy_value [[SELF_COPY]] : $Wotsit<T>
457457
// CHECK-NEXT: return [[RESULT]] : $()
458458
// CHECK-NEXT: }
459+
@objc(plain)
459460
func plain() { }
460-
// expected-warning@-1 {{access note for fancy test suite adds attribute 'objc' to this instance method}}
461-
// expected-note@-2 {{add attribute explicitly to silence this warning}} {{3-3=@objc }}
461+
// expected-warning@-2 {{access note for fancy test suite changes the '@objc' name of this instance method to 'fancy', but source code specifies 'plain'; the access note will be ignored}}
462462

463463
func generic<U>(_ x: U) {}
464464

0 commit comments

Comments
 (0)