|
5 | 5 |
|
6 | 6 | ## Swift (next) |
7 | 7 |
|
| 8 | +* [SE-0491][]: |
| 9 | + You can now use a module selector to specify which module Swift should look inside to find a named declaration. A |
| 10 | + module selector is written before the name it qualifies and consists of the module name and two colons (`::`): |
| 11 | + |
| 12 | + ```swift |
| 13 | + // This type conforms to the `View` protocol from `SwiftUI`, even if other |
| 14 | + // modules have also declared a type named `View`: |
| 15 | + struct MyView: SwiftUI::View { ... } |
| 16 | + ``` |
| 17 | + |
| 18 | + A module selector can also be applied to the name of a member; this is helpful if extensions in other modules have |
| 19 | + added an ambiguous overload: |
| 20 | + |
| 21 | + ```swift |
| 22 | + // Calls the `data(using:)` method added by `Foundation`, even if other |
| 23 | + // modules have added identical overloads of `data(using:)`. |
| 24 | + let data = "a little bit of text".Foundation::data(using: .utf8) |
| 25 | + ``` |
| 26 | + |
| 27 | + When a module selector is used, Swift skips past any enclosing scopes and starts its search at the top level of the |
| 28 | + module; this means that certain declarations, such as local variables and generic parameter types, cannot be found |
| 29 | + with a module selector. Constraints in `where` clauses also cannot use a module selector to refer to an associated |
| 30 | + type. |
| 31 | + |
| 32 | + Module selectors are primarily intended to be used when working around unavoidable conflicts, such as when two |
| 33 | + modules you don't control both use the same name. API designs which force clients to use a module selector are not |
| 34 | + recommended; it is usually better to rename a declaration instead. (19481048) |
| 35 | + |
| 36 | +* If you maintain a module built with Library Evolution, you can now configure Swift to use module selectors to improve |
| 37 | + the robustness of its module interface file. This is especially helpful if your module declares a type with the same |
| 38 | + name as the module itself. To opt in to this behavior, add the `-enable-module-selectors-in-module-interface` flag to |
| 39 | + the `OTHER_SWIFT_FLAGS` build setting. |
| 40 | + |
8 | 41 | * Concurrency-related APIs like `Task` and string-processing-related APIs like `Regex` can now be qualified by the name |
9 | 42 | `Swift`, just like other standard library APIs: |
10 | 43 |
|
@@ -10925,6 +10958,7 @@ using the `.dynamicType` member to retrieve the type of an expression should mig |
10925 | 10958 | [SE-0470]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0470-isolated-conformances.md |
10926 | 10959 | [SE-0471]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0371-isolated-synchronous-deinit.md |
10927 | 10960 | [SE-0472]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0472-task-start-synchronously-on-caller-context.md |
| 10961 | +[SE-0491]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0491-module-selectors.md |
10928 | 10962 | [#64927]: <https://github.com/apple/swift/issues/64927> |
10929 | 10963 | [#42697]: <https://github.com/apple/swift/issues/42697> |
10930 | 10964 | [#42728]: <https://github.com/apple/swift/issues/42728> |
|
0 commit comments