Skip to content

Commit 762eec3

Browse files
committed
[Sema] Always allow public overrides of open methods
1 parent bf909ca commit 762eec3

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ static void checkOverrideAccessControl(ValueDecl *baseDecl, ValueDecl *decl,
861861
}
862862
} else if (baseHasOpenAccess &&
863863
classDecl->hasOpenAccess(dc) &&
864-
decl->getFormalAccess() != AccessLevel::Open &&
864+
decl->getFormalAccess() < AccessLevel::Public &&
865865
!decl->isFinal()) {
866866
{
867867
auto diag = diags.diagnose(decl, diag::override_not_accessible,

test/attr/open.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ class SubClass : ExternalOpenClass {
7676
}
7777
}
7878

79-
open class InvalidOpenSubClass : ExternalOpenClass {
80-
public override func openMethod() {} // expected-error {{overriding instance method must be as accessible as the declaration it overrides}} {{3-9=open}}
81-
public override var openProperty: Int { get{return 0} set{} } // expected-error {{overriding property must be as accessible as the declaration it overrides}} {{3-9=open}}
82-
public override subscript(index: MarkerForOpenSubscripts) -> Int { // expected-error {{overriding subscript must be as accessible as the declaration it overrides}} {{3-9=open}}
79+
open class ValidOpenSubClass : ExternalOpenClass {
80+
public override func openMethod() {}
81+
public override var openProperty: Int { get{return 0} set{} }
82+
public override subscript(index: MarkerForOpenSubscripts) -> Int {
8383
get { return 0 }
8484
set {}
8585
}
8686
}
8787

88-
open class InvalidOpenSubClass2 : ExternalOpenClass {
88+
open class InvalidOpenSubClass : ExternalOpenClass {
8989
internal override func openMethod() {} // expected-error {{overriding instance method must be as accessible as the declaration it overrides}} {{3-11=open}}
9090
internal override var openProperty: Int { get{return 0} set{} } // expected-error {{overriding property must be as accessible as the declaration it overrides}} {{3-11=open}}
9191
internal override subscript(index: MarkerForOpenSubscripts) -> Int { // expected-error {{overriding subscript must be as accessible as the declaration it overrides}} {{3-11=open}}

test/decl/class/override.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,9 @@ class DerivedWithFilePrivateSetter: BaseWithFilePrivateSetter {
362362
}
363363
}
364364

365-
// Issues with final overrides of open members
366365
open class OpenBase {
367-
open func instanceMethod() {} // expected-note {{overridden declaration is here}}
368-
open class func classMethod() {} // expected-note {{overridden declaration is here}}
366+
open func instanceMethod() {}
367+
open class func classMethod() {}
369368
}
370369

371370
public class PublicDerived : OpenBase {
@@ -379,8 +378,8 @@ open class OpenDerived : OpenBase {
379378
}
380379

381380
open class OpenDerivedPublic : OpenBase {
382-
override public func instanceMethod() {} // expected-error {{overriding instance method must be as accessible as the declaration it overrides}}
383-
override public class func classMethod() {} // expected-error {{overriding class method must be as accessible as the declaration it overrides}}
381+
override public func instanceMethod() {} // Ok
382+
override public class func classMethod() {} // Ok
384383
}
385384

386385
open class OpenDerivedFinal : OpenBase {

0 commit comments

Comments
 (0)