Skip to content

Commit a3aa827

Browse files
committed
Warn that @objcImpl extension is deprecated
…only when the ObjCImplementation experimental language feature is enabled. (`@implementation extension` is the preferred form.)
1 parent 951eaa7 commit a3aa827

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1739,6 +1739,9 @@ ERROR(swift_native_objc_runtime_base_not_on_root_class,none,
17391739
"@_swift_native_objc_runtime_base_not_on_root_class can only be applied "
17401740
"to root classes", ())
17411741

1742+
WARNING(objc_implementation_early_spelling_deprecated,none,
1743+
"warning-only '@_objcImplementation' spelling is deprecated; use "
1744+
"'@implementation' instead", ())
17421745
ERROR(attr_objc_implementation_must_be_unconditional,none,
17431746
"only unconditional extensions can implement an Objective-C '@interface'",
17441747
())

lib/Sema/TypeCheckAttr.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,15 @@ void AttributeChecker::visitNonObjCAttr(NonObjCAttr *attr) {
15191519
static bool hasObjCImplementationFeature(Decl *D, ObjCImplementationAttr *attr,
15201520
Feature requiredFeature) {
15211521
if (D->getASTContext().LangOpts.hasFeature(requiredFeature)) {
1522+
// Encourage early ObjCImplementation adopters to adopt @implementation.
1523+
// (We'll do this for CImplementation when we're ready to stabilize it.)
1524+
if (requiredFeature == Feature::ObjCImplementation
1525+
&& attr->isEarlyAdopter())
1526+
D->getASTContext().Diags.diagnose(
1527+
attr->getLocation(),
1528+
diag::objc_implementation_early_spelling_deprecated)
1529+
.fixItReplace(attr->getLocation(), "implementation");
1530+
15221531
return true;
15231532
}
15241533

test/decl/ext/objc_implementation_features.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck %s -import-objc-header %S/Inputs/objc_implementation.h 2>&1 | %FileCheck --check-prefixes NO,CHECK %s
44
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck %s -import-objc-header %S/Inputs/objc_implementation.h -enable-experimental-feature ObjCImplementation 2>&1 | %FileCheck --check-prefixes YES,CHECK %s
55

6+
// NO-NOT: objc_implementation_features.swift:[[@LINE+2]]:{{[0-9]+}}: warning: warning-only '@_objcImplementation' spelling is deprecated; use '@implementation' instead
7+
// YES-DAG: objc_implementation_features.swift:[[@LINE+1]]:{{[0-9]+}}: warning: warning-only '@_objcImplementation' spelling is deprecated; use '@implementation' instead
68
@_objcImplementation extension ObjCSubclass {}
79

810
// NO-DAG: objc_implementation_features.swift:[[@LINE+2]]:{{[0-9]+}}: error: 'implementation' attribute is only valid when experimental feature ObjCImplementation is enabled

0 commit comments

Comments
 (0)