File: accessibility_proto.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (271 lines) | stat: -rw-r--r-- 16,140 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// RUN: %target-typecheck-verify-swift -package-name myPkg
// RUN: %target-swift-frontend -typecheck -disable-access-control -package-name myPkg %s

public protocol ProtoWithReqs {
  associatedtype AssocA // expected-note * {{type declared here}}
  associatedtype AssocB // expected-note * {{type declared here}}
  func foo()
}

public struct Adopter<T> : ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
extension Adopter {
  typealias AssocA = Int
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
  typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
  func foo() {}
  // expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
}

public struct Adopter2<T> : ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
public extension Adopter2 {
  internal typealias AssocA = Int
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-12=}}
  package typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-11=}}
  fileprivate func foo() {}
  // expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-15=}}
}

public struct Adopter3<T> : ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
internal extension Adopter3 {
  typealias AssocA = Int
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  typealias AssocB = String
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  func foo() {}
  // expected-note@-1 {{move the instance method to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
}

public struct Adopter4<T> : ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
package extension Adopter4 {
  internal typealias AssocA = Int
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  typealias AssocB = String
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  fileprivate func foo() {}
  // expected-note@-1 {{move the instance method to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
}


package protocol PkgProtoWithReqs {
  associatedtype AssocA // expected-note * {{type declared here}}
  associatedtype AssocB // expected-note * {{type declared here}}
  func foo()
}

package struct Adopter5<T> : PkgProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
extension Adopter5 {
  typealias AssocA = Int
  // expected-note@-1 {{mark the type alias as 'package' to satisfy the requirement}} {{3-3=package }}
  typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'package' to satisfy the requirement}} {{3-3=package }}
  func foo() {}
  // expected-note@-1 {{mark the instance method as 'package' to satisfy the requirement}} {{3-3=package }}
}

public class AnotherAdopterBase {
  typealias AssocA = Int
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
  package typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-10=public}}
  func foo() {}
  // expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
}
public class AnotherAdopterSub : AnotherAdopterBase, ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}

public class AnotherAdopterBase2 {}
public extension AnotherAdopterBase2 {
  internal typealias AssocA = Int
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-12=}}
  package typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-11=}}
  fileprivate func foo() {}
  // expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-15=}}
}
public class AnotherAdopterSub2 : AnotherAdopterBase2, ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}

public class AnotherAdopterBase3 {}
internal extension AnotherAdopterBase3 {
  typealias AssocA = Int
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  typealias AssocB = String
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  func foo() {}
  // expected-note@-1 {{move the instance method to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
}
public class AnotherAdopterSub3 : AnotherAdopterBase3, ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}

public class AnotherAdopterBase4 {}
package extension AnotherAdopterBase4 {
  typealias AssocA = Int
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  typealias AssocB = String
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
  func foo() {}
  // expected-note@-1 {{move the instance method to another extension where it can be declared 'public' to satisfy the requirement}} {{none}}
}
public class AnotherAdopterSub4 : AnotherAdopterBase4, ProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}

package class AnotherAdopterBase5 {}
internal extension AnotherAdopterBase5 {
  typealias AssocA = Int
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'package' to satisfy the requirement}} {{none}}
  typealias AssocB = String
  // expected-note@-1 {{move the type alias to another extension where it can be declared 'package' to satisfy the requirement}} {{none}}
  func foo() {}
  // expected-note@-1 {{move the instance method to another extension where it can be declared 'package' to satisfy the requirement}} {{none}}
}
package class AnotherAdopterSub5 : AnotherAdopterBase5, PkgProtoWithReqs {}
// expected-error@-1 {{method 'foo()' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
// expected-error@-2 {{type alias 'AssocA' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
// expected-error@-3 {{type alias 'AssocB' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}


public protocol ReqProvider {}
extension ReqProvider {
  func foo() {}
  // expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
  package typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-10=public}}
}
public struct AdoptViaProtocol : ProtoWithReqs, ReqProvider {
  // expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
  // expected-error@-2 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
  public typealias AssocA = Int
}

internal protocol InternalProtoWithReqs {
  associatedtype AssocA // expected-note * {{type declared here}}
  associatedtype AssocB // expected-note * {{type declared here}}
  func foo()
}

internal protocol InternalReqProvider {}
extension InternalReqProvider {
  fileprivate func foo() {}
  // expected-note@-1 {{mark the instance method as 'internal' to satisfy the requirement}} {{3-14=internal}}
  fileprivate typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'internal' to satisfy the requirement}} {{3-14=internal}}
}
internal struct InternalAdoptViaProtocol : InternalProtoWithReqs, InternalReqProvider {
  // expected-error@-1 {{method 'foo()' must be declared internal because it matches a requirement in internal protocol 'InternalProtoWithReqs'}} {{none}}
  // expected-error@-2 {{type alias 'AssocB' must be declared internal because it matches a requirement in internal protocol 'InternalProtoWithReqs'}} {{none}}
  internal typealias AssocA = Int
}

public protocol ReqProvider2 {}
extension ProtoWithReqs where Self : ReqProvider2 {
  func foo() {}
  // expected-note@-1 {{mark the instance method as 'public' to satisfy the requirement}} {{3-3=public }}
  typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'public' to satisfy the requirement}} {{3-3=public }}
}
public struct AdoptViaCombinedProtocol : ProtoWithReqs, ReqProvider2 {
  // expected-error@-1 {{method 'foo()' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
  // expected-error@-2 {{type alias 'AssocB' must be declared public because it matches a requirement in public protocol 'ProtoWithReqs'}} {{none}}
  public typealias AssocA = Int
}

public protocol PublicInitProto {
  var value: Int { get }
  init(value: Int)
}
public struct NonPublicInitStruct: PublicInitProto {
  public var value: Int
  init(value: Int) {
  // expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
  // expected-note@-2 {{mark the initializer as 'public' to satisfy the requirement}}
    self.value = value
  }
}
public struct NonPublicMemberwiseInitStruct: PublicInitProto {
// expected-error@-1 {{initializer 'init(value:)' must be declared public because it matches a requirement in public protocol 'PublicInitProto'}}
  public var value: Int
}

package protocol PackageInitProto {
  var value: Int { get }
  init(value: Int)
}
package struct NonPackageInitStruct: PackageInitProto {
  package var value: Int
  init(value: Int) {
  // expected-error@-1 {{initializer 'init(value:)' must be declared package because it matches a requirement in package protocol 'PackageInitProto'}}
  // expected-note@-2 {{mark the initializer as 'package' to satisfy the requirement}}
    self.value = value
  }
}
package struct NonPackageMemberwiseInitStruct: PackageInitProto {
// expected-error@-1 {{initializer 'init(value:)' must be declared package because it matches a requirement in package protocol 'PackageInitProto'}}
  public var value: Int
}

// https://github.com/apple/swift/issues/57595

public protocol PublicEmptyInit {
  init()
}
public struct Buggy: PublicEmptyInit { 
  // expected-error@-1 {{initializer 'init()' must be declared public because it matches a requirement in public protocol 'PublicEmptyInit'}}
}

package protocol PkgEmptyInit {
  init()
}
public struct PkgBuggy: PkgEmptyInit {
  // expected-error@-1 {{initializer 'init()' must be declared package because it matches a requirement in package protocol 'PkgEmptyInit'}}
}

package protocol PkgReqProvider {}
extension PkgReqProvider {
  fileprivate func foo() {}
  // expected-note@-1 {{mark the instance method as 'package' to satisfy the requirement}} {{3-14=package}}
  typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'package' to satisfy the requirement}} {{3-3=package }}
}
package struct PkgAdoptViaProtocol : PkgProtoWithReqs, PkgReqProvider {
  // expected-error@-1 {{method 'foo()' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
  // expected-error@-2 {{type alias 'AssocB' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
  package typealias AssocA = Int
}

package protocol PkgReqProvider2 {}
extension PkgProtoWithReqs where Self : PkgReqProvider2 {
  func foo() {}
  // expected-note@-1 {{mark the instance method as 'package' to satisfy the requirement}} {{3-3=package }}
  typealias AssocB = String
  // expected-note@-1 {{mark the type alias as 'package' to satisfy the requirement}} {{3-3=package }}
}
package struct PkgAdoptViaCombinedProtocol : PkgProtoWithReqs, PkgReqProvider2 {
  // expected-error@-1 {{method 'foo()' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
  // expected-error@-2 {{type alias 'AssocB' must be declared package because it matches a requirement in package protocol 'PkgProtoWithReqs'}} {{none}}
  public typealias AssocA = Int
}