Skip to content

Commit f66da2e

Browse files
authored
Merge pull request #4403 from rintaro/requirement-accessibility
[Sema] Minimum access for protocol requirement members to 'fileprivate'.
2 parents d0b95dc + 2662781 commit f66da2e

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-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
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
// RUN: %utils/split_file.py -o %t %s
3+
// RUN: %target-swift-frontend -parse %t/file1.swift -primary-file %t/file2.swift -verify
4+
5+
// BEGIN file1.swift
6+
private protocol P {
7+
func privMethod()
8+
}
9+
public class C : P {
10+
public init() {}
11+
fileprivate func privMethod() {}
12+
}
13+
14+
// BEGIN file2.swift
15+
extension C {
16+
public func someFunc() {
17+
privMethod() // expected-error {{use of unresolved identifier 'privMethod'}}
18+
}
19+
}

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)