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
structS {
privatetypealiasT = Int
}
privateextensionS {
varp: T { 0 } // error: property must be declared private because its type uses a private type
}
One reasonable expectation is that code behaves as-if the inner property is also marked private. However, that's the case, it behaves as-if the outer extension (and the inner property) are marked fileprivate. Arguably, we should do the following to improve the diagnostic and make the code clearer:
1. Provide some more explanation: In the case where such a property (subscript etc.) is inside a private extension – perhaps we should point out that an extension marked private is implicitly treated as fileprivate.
2. We should offer a fix-it to add the right annotation (I don't think we are doing this already), and perhaps update the extension's privacy to say fileprivate instead of private so it's clearer because that's what it really means (otherwise, some beginner reading the code may be surprised to see the duplicated private).
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: 8fe9d01d9a2a8a667aa181d42aedbfa2
Issue Description:
Confusion between fileprivate and private extensions is somewhat common; this question on StackOverflow (https://stackoverflow.com/questions/43287220/difference-between-fileprivate-and-private-extension) is at +11 right now.
This leads to surprising behavior sometimes.
One reasonable expectation is that code behaves as-if the inner property is also marked
private
. However, that's the case, it behaves as-if the outer extension (and the inner property) are markedfileprivate
. Arguably, we should do the following to improve the diagnostic and make the code clearer:1. Provide some more explanation: In the case where such a property (subscript etc.) is inside a
private
extension – perhaps we should point out that an extension markedprivate
is implicitly treated asfileprivate
.2. We should offer a fix-it to add the right annotation (I don't think we are doing this already), and perhaps update the extension's privacy to say
fileprivate
instead ofprivate
so it's clearer because that's what it really means (otherwise, some beginner reading the code may be surprised to see the duplicatedprivate
).The text was updated successfully, but these errors were encountered: