Skip to content

Commit 87ee594

Browse files
committed
[Sema] Minimum access for protocol requirement members to 'fileprivate'.
It used to be `internal`. // ModA/File1.swift private protocol P { func privMethod() // This was implicitly `internal`. } public class C { public init() {} fileprivate func privMethod() { print("FOOBAR") } } // ModA/File2.swift extension C { public func callPrivMethod() { // This should be "error: use of unresolved identifier 'foo'", // but was not. privMethod() } } // main.swift // This ends up runtime error 'fatal error: : call of deleted method' C().callPrivMethod()
1 parent d3d2b0a commit 87ee594

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,8 @@ void TypeChecker::computeAccessibility(ValueDecl *D) {
13881388
validateAccessibility(generic);
13891389
Accessibility access = Accessibility::Internal;
13901390
if (isa<ProtocolDecl>(generic))
1391-
access = std::max(access, generic->getFormalAccess());
1391+
access = std::max(Accessibility::FilePrivate,
1392+
generic->getFormalAccess());
13921393
D->setAccessibility(access);
13931394
break;
13941395
}

test/IDE/complete_override_access_control.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,16 @@ public class TestPublicABC : ProtocolAPrivate, ProtocolBInternal, ProtocolCPubli
112112

113113
// TEST_INTERNAL_ABC: Begin completions, 15 items
114114
// TEST_INTERNAL_ABC-DAG: Decl[Constructor]/Super: init(fromProtocolA: TagPA) {|}{{; name=.+$}}
115-
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: func protoAFunc(x: TagPA) {|}{{; name=.+$}}
116-
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: func protoAFuncOptional(x: TagPA) {|}{{; name=.+$}}
115+
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: fileprivate func protoAFunc(x: TagPA) {|}{{; name=.+$}}
116+
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: fileprivate func protoAFuncOptional(x: TagPA) {|}{{; name=.+$}}
117117
// TEST_INTERNAL_ABC-DAG: Decl[Constructor]/Super: init(fromProtocolB: TagPB) {|}{{; name=.+$}}
118118
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: func protoBFunc(x: TagPB) {|}{{; name=.+$}}
119119
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: func protoBFuncOptional(x: TagPB) {|}{{; name=.+$}}
120120
// TEST_INTERNAL_ABC-DAG: Decl[Constructor]/Super: init(fromProtocolC: TagPC) {|}{{; name=.+$}}
121121
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: func protoCFunc(x: TagPC) {|}{{; name=.+$}}
122122
// TEST_INTERNAL_ABC-DAG: Decl[InstanceMethod]/Super: func protoCFuncOptional(x: TagPC) {|}{{; name=.+$}}
123-
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: var protoAVarRW: TagPA
124-
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: var protoAVarRO: TagPA
123+
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: fileprivate var protoAVarRW: TagPA
124+
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: fileprivate var protoAVarRO: TagPA
125125
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: var protoBVarRW: TagPB
126126
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: var protoBVarRO: TagPB
127127
// TEST_INTERNAL_ABC-DAG: Decl[InstanceVar]/Super: var protoCVarRW: TagPC
@@ -130,16 +130,16 @@ public class TestPublicABC : ProtocolAPrivate, ProtocolBInternal, ProtocolCPubli
130130

131131
// TEST_PUBLIC_ABC: Begin completions, 15 items
132132
// TEST_PUBLIC_ABC-DAG: Decl[Constructor]/Super: init(fromProtocolA: TagPA) {|}{{; name=.+$}}
133-
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: func protoAFunc(x: TagPA) {|}{{; name=.+$}}
134-
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: func protoAFuncOptional(x: TagPA) {|}{{; name=.+$}}
133+
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: fileprivate func protoAFunc(x: TagPA) {|}{{; name=.+$}}
134+
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: fileprivate func protoAFuncOptional(x: TagPA) {|}{{; name=.+$}}
135135
// TEST_PUBLIC_ABC-DAG: Decl[Constructor]/Super: init(fromProtocolB: TagPB) {|}{{; name=.+$}}
136136
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: func protoBFunc(x: TagPB) {|}{{; name=.+$}}
137137
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: func protoBFuncOptional(x: TagPB) {|}{{; name=.+$}}
138138
// TEST_PUBLIC_ABC-DAG: Decl[Constructor]/Super: init(fromProtocolC: TagPC) {|}{{; name=.+$}}
139139
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: public func protoCFunc(x: TagPC) {|}{{; name=.+$}}
140140
// TEST_PUBLIC_ABC-DAG: Decl[InstanceMethod]/Super: public func protoCFuncOptional(x: TagPC) {|}{{; name=.+$}}
141-
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: var protoAVarRW: TagPA
142-
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: var protoAVarRO: TagPA
141+
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: fileprivate var protoAVarRW: TagPA
142+
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: fileprivate var protoAVarRO: TagPA
143143
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: var protoBVarRW: TagPB
144144
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: var protoBVarRO: TagPB
145145
// TEST_PUBLIC_ABC-DAG: Decl[InstanceVar]/Super: public var protoCVarRW: TagPC

test/attr/accessibility_print.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public enum DC_PublicEnum {
122122
private protocol EA_PrivateProtocol {
123123
// CHECK: {{^}} associatedtype Foo
124124
associatedtype Foo
125-
// CHECK: internal var Bar
125+
// CHECK: fileprivate var Bar
126126
var Bar: Int { get }
127-
// CHECK: internal func baz()
127+
// CHECK: fileprivate func baz()
128128
func baz()
129129
} // CHECK: {{^[}]}}
130130

0 commit comments

Comments
 (0)