Skip to content

Commit 6a0834f

Browse files
committed
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'.
1 parent 531ad28 commit 6a0834f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,8 +2177,9 @@ ERROR(access_control_open_bad_decl,none,
21772177
"only classes and overridable class members can be declared 'open';"
21782178
" use 'public'", ())
21792179
ERROR(access_control_non_objc_open_member,none,
2180-
"non-'@objc' %0 in extensions cannot be overridden; use 'public' instead",
2181-
(DescriptiveDeclKind))
2180+
"non-'@objc' %kindonly0 declared in extension cannot be overridden; use "
2181+
"'public' instead",
2182+
(const ValueDecl *))
21822183
ERROR(access_control_requires_package_name, none,
21832184
"the package access level %select{|used on %1 }0"
21842185
"requires a package name; set it with the compiler flag -package-name",

lib/Sema/TypeCheckAttr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,8 +1327,7 @@ void AttributeChecker::visitAccessControlAttr(AccessControlAttr *attr) {
13271327
// an extension.
13281328
if (!VD->isObjC() && attr->getAccess() == AccessLevel::Open) {
13291329
diagnose(attr->getLocation(),
1330-
diag::access_control_non_objc_open_member,
1331-
VD->getDescriptiveKind())
1330+
diag::access_control_non_objc_open_member, VD)
13321331
.fixItReplace(attr->getRange(), "public")
13331332
.warnUntilSwiftVersion(7);
13341333
}

test/attr/open_objc.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ open class InvalidOpenExtension {
99
open var openVar: Int { 3 } // No warning: Pure Swift properties can be open inside the class declaration.
1010
}
1111
extension InvalidOpenExtension {
12-
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}}
13-
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}}
14-
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}}
15-
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}}
16-
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}}
12+
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}}
13+
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}}
14+
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}}
15+
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}}
16+
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}}
1717

1818
@objc open func objcOpenMethod() { } // No warning: @objc methods can be open inside extensions.
1919
@objc open var objcOpenVar: Int { 3 } // No warning: @objc methods can be open inside extensions.

0 commit comments

Comments
 (0)