Can explicitly assign tuple access level in Swift
| Originator: | scott.eric.gardner | ||
| Number: | rdar://18609052 | Date Originated: | 10/10/14 |
| Status: | Open | Resolved: | |
| Product: | Swift | Product Version: | 1.0 |
| Classification: | Reproducible: | Yes |
The Swift language guide states, "…if you compose a tuple from two different types, one with internal access and one with private access, the access level for that compound tuple type will be private.," and, "A tuple type’s access level is deduced automatically when the tuple type is used, and cannot be specified explicitly." However, as demonstrated in sample code provided with the bug report, a tuple’s type _can_ be explicitly assigned, and in the case of a tuple defined in an imported module, the tuple itself _must_ be explicitly assigned public access in order to be accessible within the importing module, and doing so overrides whatever explicit access control has been assigned to its elements. This behavior is similar to the way mutability is inherited. Steps to reproduce: See enclosed project code, specifically... 1. CustomTypes.swift - defines and explicitly specifies public access to a tuple composed of private elements 2. CustomFrameworkTypes.swift - defines and explicitly specifies public access to a tuple composed of private elements 3. ViewController.swift - imports and creates instances of the tuples defined in steps 1 & 2 Expected Results: According to the Swift language guide, the tuples' access level should not have been able to be explicitly set, and therefore, since each tuple was comprised of private elements, the tuples' access levels should also have been private and not accessible within a different source file. Actual Results: The tuples were able to have an access level explicitly specified, which overrode the implicit access level that should have been deduced from the most restrictive access level of the elements of the tuple.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!