Sema: Minor improvements to access_control_non_objc_open_member message

* Use the '%kindonly' specifier.
* Make the object and its modifier agree on grammatical number.
* 'in extension' → 'declared in extension'.
This commit is contained in:
Anthony Latsis
2025-01-12 15:27:57 +00:00
parent 531ad28996
commit 6a0834f2fc
3 changed files with 9 additions and 9 deletions

View File

@@ -2177,8 +2177,9 @@ ERROR(access_control_open_bad_decl,none,
"only classes and overridable class members can be declared 'open';"
" use 'public'", ())
ERROR(access_control_non_objc_open_member,none,
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
(DescriptiveDeclKind))
"non-'@objc' %kindonly0 declared in extension cannot be overridden; use "
"'public' instead",
(const ValueDecl *))
ERROR(access_control_requires_package_name, none,
"the package access level %select{|used on %1 }0"
"requires a package name; set it with the compiler flag -package-name",

View File

@@ -1327,8 +1327,7 @@ void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
// an extension.
if (!VD->isObjC() && attr->getAccess() == AccessLevel::Open) {
diagnose(attr->getLocation(),
diag::access_control_non_objc_open_member,
VD->getDescriptiveKind())
diag::access_control_non_objc_open_member, VD)
.fixItReplace(attr->getRange(), "public")
.warnUntilSwiftVersion(7);
}

View File

@@ -9,11 +9,11 @@ open class InvalidOpenExtension {
open var openVar: Int { 3 } // No warning: Pure Swift properties can be open inside the class declaration.
}
extension InvalidOpenExtension {
open func nonObjcOpenMethod() { } // expected-warning {{non-'@objc' instance method in extensions cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open class func nonObjcOpenMethod() { } // expected-warning {{non-'@objc' class method in extensions cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open var nonObjcOpenVar: Int { 3 } // expected-warning {{non-'@objc' property in extensions cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open subscript(_ index: Int) -> Int { 3 } // expected-warning {{non-'@objc' subscript in extensions cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open convenience init(index: Int) { self.init() } // expected-error {{only classes and overridable class members can be declared 'open'; use 'public'}} // expected-warning {{non-'@objc' initializer in extensions cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}}
open func nonObjcOpenMethod() { } // expected-warning {{non-'@objc' instance method declared in extension cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open class func nonObjcOpenMethod() { } // expected-warning {{non-'@objc' class method declared in extension cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open var nonObjcOpenVar: Int { 3 } // expected-warning {{non-'@objc' property declared in extension cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open subscript(_ index: Int) -> Int { 3 } // expected-warning {{non-'@objc' subscript declared in extension cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}} {{3-7=public}}
open convenience init(index: Int) { self.init() } // expected-error {{only classes and overridable class members can be declared 'open'; use 'public'}} // expected-warning {{non-'@objc' initializer declared in extension cannot be overridden; use 'public' instead; this will be an error in a future Swift language mode}}
@objc open func objcOpenMethod() { } // No warning: @objc methods can be open inside extensions.
@objc open var objcOpenVar: Int { 3 } // No warning: @objc methods can be open inside extensions.