New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-13196] Implicit access level for private
type disagrees with TSPL
#55636
Comments
Comment by Connor Hanley (JIRA) Would be nice to have a built-in function called accessControl(of: ), similar to type(of: ), to better understand what's going on with these types of examples. |
This is an error in TSPL: what it claims is not what was approved during the Swift Evolution process and subsequently implemented. The members are bounded by, and have the same effective visibility as, that of the containing type; they explicitly do not have the same access level. Otherwise, a nested private type could never have members that have the same visibility as itself. |
Comment by Frederick Kellison-Linn (JIRA) Right, I should have been clearer—this is a "bug" in TSPL. |
Comment by Connor Hanley (JIRA) @xwu thanks for pointing this out. This issue came from a Swift.org post where I was trying to understand the language better. Would it be fair to say that Swift and its compiler generally try to direct the programmer to write things out explicitly, rather than rely on implicit behavior? It seems like confusion would inevitably arise, were the behavior cited in TSPL actually implemented. Just to make sure I'm understanding your example correctly, a private nested type is a perfectly natural thing, but a developer wouldn't expect the parent type to not have access to members of the nested type, right? If I'm writing a nested type, I would expect the parent type to have full access to what's within it, unless I explicitly set the nested type's members to private. Do you happen to have a link to the discussion on the Swift Evolution that led to this conclusion? I would love to read it. |
Comment by Connor Hanley (JIRA) Also, how much of TSPL is out of date here? Do any of the other access control levels on types result in implicit levels for the type's members? I remember that a public type will implicitly make its members internal, which makes sense, but does a file-private type imply that its members file-private? |
The implicit access level is always 'internal', but no member can be more visible than the type it's declared in. |
@swift-ci create |
Additional Detail from JIRA
md5: 68f121b5cd3344a28e179217c9db1081
Issue Description:
The Swift Programming Language, it its access control section, makes the following claim:
The associated example reads (in part):
However, the "implicitly private" part doesn't seem to pan out in actuality. E.g., `A.x` in the following example appears to have `fileprivate` access (at least):
The text was updated successfully, but these errors were encountered: