Skip to content

Commit f1856b8

Browse files
committed
Honor !EnableAccessControl when checking protocol witnesses
Useful in the LLDB REPL, and also for what I'm about to do to the integrated REPL.
1 parent 56f7164 commit f1856b8

File tree

3 files changed

+66
-62
lines changed

3 files changed

+66
-62
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,8 @@ bool WitnessChecker::checkWitnessAccess(AccessScope &requiredAccessScope,
11561156
ValueDecl *witness,
11571157
bool *isSetter) {
11581158
*isSetter = false;
1159+
if (!TC.getLangOpts().EnableAccessControl)
1160+
return false;
11591161

11601162
// Compute the intersection of the conforming type's access scope
11611163
// and the protocol's access scope.

test/attr/accessibility.swift

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -208,68 +208,6 @@ extension GenericStruct where Param: InternalProto {
208208
}
209209

210210

211-
public protocol ProtoWithReqs {
212-
associatedtype Assoc
213-
func foo()
214-
}
215-
216-
public struct Adopter<T> : ProtoWithReqs {}
217-
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
218-
// expected-error@-2 {{type alias 'Assoc' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
219-
extension Adopter {
220-
typealias Assoc = Int
221-
// expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
222-
func foo() {}
223-
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
224-
}
225-
226-
public class AnotherAdopterBase {
227-
typealias Assoc = Int
228-
// expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
229-
func foo() {}
230-
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
231-
}
232-
public class AnotherAdopterSub : AnotherAdopterBase, ProtoWithReqs {}
233-
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
234-
// expected-error@-2 {{type alias 'Assoc' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
235-
236-
public protocol ReqProvider {}
237-
extension ReqProvider {
238-
func foo() {}
239-
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
240-
}
241-
public struct AdoptViaProtocol : ProtoWithReqs, ReqProvider {
242-
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
243-
public typealias Assoc = Int
244-
}
245-
246-
public protocol ReqProvider2 {}
247-
extension ProtoWithReqs where Self : ReqProvider2 {
248-
func foo() {}
249-
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
250-
}
251-
public struct AdoptViaCombinedProtocol : ProtoWithReqs, ReqProvider2 {
252-
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
253-
public typealias Assoc = Int
254-
}
255-
256-
public protocol PublicInitProto {
257-
var value: Int { get }
258-
init(value: Int)
259-
}
260-
public struct NonPublicInitStruct: PublicInitProto {
261-
public var value: Int
262-
init(value: Int) {
263-
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
264-
// expected-note@-2 {{mark the initializer as 'public' to satisfy the requirement}}
265-
self.value = value
266-
}
267-
}
268-
public struct NonPublicMemberwiseInitStruct: PublicInitProto {
269-
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
270-
public var value: Int
271-
}
272-
273211
public class OuterClass {
274212
class InnerClass {}
275213
}

test/attr/accessibility_proto.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// RUN: %target-typecheck-verify-swift
2+
// RUN: %target-swift-frontend -typecheck -disable-access-control %s
3+
4+
public protocol ProtoWithReqs {
5+
associatedtype Assoc
6+
func foo()
7+
}
8+
9+
public struct Adopter<T> : ProtoWithReqs {}
10+
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
11+
// expected-error@-2 {{type alias 'Assoc' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
12+
extension Adopter {
13+
typealias Assoc = Int
14+
// expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
15+
func foo() {}
16+
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
17+
}
18+
19+
public class AnotherAdopterBase {
20+
typealias Assoc = Int
21+
// expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
22+
func foo() {}
23+
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
24+
}
25+
public class AnotherAdopterSub : AnotherAdopterBase, ProtoWithReqs {}
26+
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
27+
// expected-error@-2 {{type alias 'Assoc' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
28+
29+
public protocol ReqProvider {}
30+
extension ReqProvider {
31+
func foo() {}
32+
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
33+
}
34+
public struct AdoptViaProtocol : ProtoWithReqs, ReqProvider {
35+
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
36+
public typealias Assoc = Int
37+
}
38+
39+
public protocol ReqProvider2 {}
40+
extension ProtoWithReqs where Self : ReqProvider2 {
41+
func foo() {}
42+
// expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
43+
}
44+
public struct AdoptViaCombinedProtocol : ProtoWithReqs, ReqProvider2 {
45+
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
46+
public typealias Assoc = Int
47+
}
48+
49+
public protocol PublicInitProto {
50+
var value: Int { get }
51+
init(value: Int)
52+
}
53+
public struct NonPublicInitStruct: PublicInitProto {
54+
public var value: Int
55+
init(value: Int) {
56+
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
57+
// expected-note@-2 {{mark the initializer as 'public' to satisfy the requirement}}
58+
self.value = value
59+
}
60+
}
61+
public struct NonPublicMemberwiseInitStruct: PublicInitProto {
62+
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
63+
public var value: Int
64+
}

0 commit comments

Comments
 (0)