Hi evolution community, I would like to propose "Scoped @available" attribute.
What I want to achieve is to declare something that is publicly unavailable, but still usable from narrower scope. A concrete example is IndexableBase in the standard library: https://github.com/apple/swift/blob/master/stdlib/ public/core/Collection.swift#L18-L20 Workaround for this problem in stdlib is to use typealias to underscored declaration. However, we can't use this technique in our module because underscored declarations are still visible and usable from outside. As a solution, I propose to add "access" parameter to @available attribute, which limits the effect of @available attribute to the specified value or outer. --- // Module: Library /// This protocol is available for internal, but deprecated for public. @available(*, deprecated, access: public, message: "it will be removed in future") public protocol OldProtocol { /* ... */ } public Foo: OldProtocol { // No diagnostics } --- // Module: main import Library public Bar: OldProtocol { // warning: 'OldProtocol' is deprecated: it will be removed in future } --- I think this is useful when you want to stop exposing declarations, but want to keep using them internally. More examples: // is `open`, going to be `filerprivate` @available(*, deprecated, access: internal) open class Foo {} // was `internal`, now `private` @available(*, unavailable, access: fileprivate) var value: Int // No effect (invisible from public anyway): emit a warning @available(*, unavailable, access: public) internal struct Foo {} What do you think?
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
