You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Private members may not satisfy protocol requirements, ever. (#3842)
* Private members may not satisfy protocol requirements, ever.
...because by construction they can be invoked from outside of the
type.
Finishing up SE-0025 ('private' and 'fileprivate').
* Update docs and mark SE-0025 ('private' and 'fileprivate') as done!
There's still improvements we can make (see 508e825), but the feature
is in place and should be working correctly.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,8 @@ Note: This is in reverse chronological order, so newer entries are added to the
3
3
Swift 3.0
4
4
---------
5
5
6
+
*[SE-0025](https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md): A declaration marked as `private` can now only be accessed within the lexical scope it is declared in (essentially the enclosing curly braces `{}`). A `private` declaration at the top level of a file can be accessed anywhere in that file, as in Swift 2. The access level formerly known as `private` is now called `fileprivate`.
privatestructTheType{} // expected-error {{struct 'TheType' must be as accessible as its enclosing type because it matches a requirement in protocol 'TypeProto'}} {{3-10=fileprivate}}
privatefunc publicReq(){} // expected-error {{method 'publicReq()' must be declared public because it matches a requirement in public protocol 'PublicProto'}} {{3-10=public}}
23
23
privatefunc internalReq(){} // expected-error {{method 'internalReq()' must be declared internal because it matches a requirement in internal protocol 'InternalProto'}} {{3-10=internal}}
24
24
privatefunc filePrivateReq(){} // expected-error {{method 'filePrivateReq()' must be declared fileprivate because it matches a requirement in fileprivate protocol 'FilePrivateProto'}} {{3-10=fileprivate}}
25
-
privatefunc privateReq(){}
25
+
privatefunc privateReq(){} // expected-error {{method 'privateReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PrivateProto'}} {{3-10=fileprivate}}
privatefunc publicReq(){} // expected-error {{method 'publicReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PublicProto'}} {{3-10=internal}}
33
33
privatefunc internalReq(){} // expected-error {{method 'internalReq()' must be declared internal because it matches a requirement in internal protocol 'InternalProto'}} {{3-10=internal}}
34
34
privatefunc filePrivateReq(){} // expected-error {{method 'filePrivateReq()' must be declared fileprivate because it matches a requirement in fileprivate protocol 'FilePrivateProto'}} {{3-10=fileprivate}}
35
-
privatefunc privateReq(){}
35
+
privatefunc privateReq(){} // expected-error {{method 'privateReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PrivateProto'}} {{3-10=fileprivate}}
privatefunc publicReq(){} // expected-error {{method 'publicReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PublicProto'}} {{3-10=fileprivate}}
43
43
privatefunc internalReq(){} // expected-error {{method 'internalReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'InternalProto'}} {{3-10=fileprivate}}
44
44
privatefunc filePrivateReq(){} // expected-error {{method 'filePrivateReq()' must be declared fileprivate because it matches a requirement in fileprivate protocol 'FilePrivateProto'}} {{3-10=fileprivate}}
45
-
privatefunc privateReq(){}
45
+
privatefunc privateReq(){} // expected-error {{method 'privateReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PrivateProto'}} {{3-10=fileprivate}}
privatefunc publicReq(){} // expected-error {{method 'publicReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PublicProto'}} {{3-10=fileprivate}}
53
+
privatefunc internalReq(){} // expected-error {{method 'internalReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'InternalProto'}} {{3-10=fileprivate}}
54
+
privatefunc filePrivateReq(){} // expected-error {{method 'filePrivateReq()' must be declared fileprivate because it matches a requirement in fileprivate protocol 'FilePrivateProto'}} {{3-10=fileprivate}}
55
+
privatefunc privateReq(){} // expected-error {{method 'privateReq()' must be as accessible as its enclosing type because it matches a requirement in protocol 'PrivateProto'}} {{3-10=fileprivate}}
Copy file name to clipboardExpand all lines: test/Sema/accessibility_private.swift
+35Lines changed: 35 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -110,3 +110,38 @@ class Sub : Container {
110
110
varsubInner:PrivateInner? // FIXME expected-error {{use of undeclared type 'PrivateInner'}}
111
111
varsubInnerQualified:Container.PrivateInner? // FIXME expected-error {{'PrivateInner' is not a member type of 'Container'}}
112
112
}
113
+
114
+
115
+
protocolVeryImportantProto{
116
+
associatedtypeAssoc
117
+
varvalue:Int{getset} // expected-note {{protocol requires property 'value' with type 'Int'; do you want to add a stub?}}
118
+
}
119
+
120
+
privatestructVIPPrivateType:VeryImportantProto{
121
+
privatetypealiasAssoc=Int // expected-error {{type alias 'Assoc' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}}
122
+
varvalue:Int
123
+
}
124
+
125
+
privatestructVIPPrivateProp:VeryImportantProto{
126
+
typealiasAssoc=Int
127
+
privatevarvalue:Int // expected-error {{property 'value' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{3-10=fileprivate}}
private(set)varvalue:Int // expected-error {{setter for property 'value' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{3-10=fileprivate}}
133
+
}
134
+
135
+
privateclassVIPPrivateSetBase{
136
+
privatevarvalue:Int=0
137
+
}
138
+
privateclassVIPPrivateSetSub:VIPPrivateSetBase,VeryImportantProto{ // expected-error {{type 'VIPPrivateSetSub' does not conform to protocol 'VeryImportantProto'}}
139
+
typealiasAssoc=Int
140
+
}
141
+
142
+
privateclassVIPPrivateSetPropBase{
143
+
private(set)varvalue:Int=0 // expected-error {{setter for property 'value' must be as accessible as its enclosing type because it matches a requirement in protocol 'VeryImportantProto'}} {{3-10=fileprivate}}
0 commit comments