Skip to content

Commit 89ae325

Browse files
committed
Use Formal Access To Compute Override Elision Check
The effective access of an overridden declaration is subject to escalation by -enable-testing. When this is flag is enabled, an interface containing an internal-overriding-public declaration will still print `override`. This is because the effective access of the base of the override is formally internal but effectively public. Instead, use the formal access scope of the overridden declaration to compute its access relative to the override. While I'm here, catch the case where the base declaration is `@usableFromInline` and therefore *will* be printed in the interface. We treat these declarations as effectively public for the purpose of printing `override`. Resolves rdar://64969741
1 parent 30ccb52 commit 89ae325

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/AST/Attr.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,11 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
749749
if (auto *VD = dyn_cast<ValueDecl>(D)) {
750750
if (auto *BD = VD->getOverriddenDecl()) {
751751
if (!BD->hasClangNode() &&
752-
VD->isEffectiveLinkageMoreVisibleThan(BD))
752+
!BD->getFormalAccessScope(VD->getDeclContext(),
753+
/*treatUsableFromInlineAsPublic*/ true)
754+
.isPublic()) {
753755
return false;
756+
}
754757
}
755758
}
756759
break;

test/ModuleInterface/skip-override-keyword.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,23 @@
22
// RUN: %target-swift-frontend -typecheck -module-name Foo -emit-module-interface-path %t/Foo.swiftinterface %s
33
// RUN: %target-swift-frontend -compile-module-from-interface %t/Foo.swiftinterface -o %t/Foo.swiftmodule
44

5+
// RUN: %target-swift-frontend -typecheck -enable-testing -module-name FooWithTesting -emit-module-interface-path %t/FooWithTesting.swiftinterface %s
6+
// RUN: %target-swift-frontend -compile-module-from-interface %t/FooWithTesting.swiftinterface -o %t/FooWithTesting.swiftmodule
7+
58
public class BaseClass {
9+
init() { }
610
var property: Int { return 1 }
711
func doSomething() { }
812
subscript(index: Int) -> Int { get { return 0 } set(newValue) {} }
13+
@usableFromInline func doSomethingInline() {}
14+
@usableFromInline func doSomethingUsableFromInline() {}
915
}
16+
1017
public class DerivedClass: BaseClass {
18+
public override init() { super.init() }
1119
public override var property : Int { return 0 }
1220
public override func doSomething() { }
1321
public override subscript(index: Int) -> Int { get {return 0} set(newValue) {} }
22+
@inlinable public override func doSomethingInline() { super.doSomethingInline() }
23+
@usableFromInline override func doSomethingUsableFromInline() { super.doSomethingUsableFromInline() }
1424
}

0 commit comments

Comments
 (0)