This would be very useful, but the spelling needs dramatic improvement.<br><br>&quot;Available unavailable&quot; is already challenging to read, but at least it is learnable with time. The example where &quot;@available(*, deprecated, access: internal) open&quot; means &quot;fileprivate&quot; is entirely unreasonable.<br><br><div class="gmail_quote"><div dir="ltr">On Sun, Jul 9, 2017 at 22:40 rintaro ishizaki via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi evolution community,<div><br></div><div>I would like to propose &quot;Scoped @available&quot; attribute.</div><div><br></div><div>What I want to achieve is to declare something that is publicly unavailable, but still usable from narrower scope. A concrete example is <font face="monospace, monospace">IndexableBase</font> in the standard library:</div><div><div><a href="https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L18-L20" target="_blank">https://github.com/apple/swift/blob/master/stdlib/public/core/Collection.swift#L18-L20</a><br></div><div>Workaround for this problem in stdlib is to use <font face="monospace, monospace">typealias</font> to underscored declaration. However, we can&#39;t use this technique in our module because underscored declarations are still visible and usable from outside.</div><div><br></div></div><div>As a solution, I propose to add <font face="monospace, monospace">&quot;access&quot;</font> parameter to <font face="monospace, monospace">@available</font> attribute, which limits the effect of <font face="monospace, monospace">@available</font> attribute to the specified value or outer.<br><br></div><div>---</div><div><font face="monospace, monospace">// Module: Library<br><br>/// This protocol is available for internal, but deprecated for public.<br>@available(*, deprecated, access: public, message: &quot;it will be </font><span style="font-family:monospace,monospace">removed</span><font face="monospace, monospace"> in future&quot;)<br>public protocol OldProtocol {<br>    /* ... */<br>}<br><br>public Foo: OldProtocol { // No diagnostics<br>}</font></div><div><font face="monospace, monospace"><br></font><div>---</div><font face="monospace, monospace">// Module: main</font></div><div><font face="monospace, monospace"><br>import Library<br><br>public Bar: OldProtocol { // warning: &#39;OldProtocol&#39; is deprecated: it will be removed in future<br>}</font></div><div><font face="monospace, monospace"><br></font></div><div><div>---</div></div><div><br></div><div>I think this is useful when you want to stop exposing declarations, but want to keep using them internally.</div><div><br></div><div>More examples:</div><div><br></div><div><font face="monospace, monospace">// is `open`, going to be `filerprivate`</font></div><div><font face="monospace, monospace">@available(*, deprecated, access: internal)</font></div><div><font face="monospace, monospace">open class Foo {}</font></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">// was `internal`, now `private`</font></div><div><font face="monospace, monospace">@available(*, unavailable, access: fileprivate)</font></div><div><font face="monospace, monospace">var value: Int</font></div><div><font face="monospace, monospace"><br></font></div></div><div><font face="monospace, monospace">// No effect (invisible from public anyway): emit a warning</font></div><div><div><font face="monospace, monospace">@available(*, unavailable, access: public)</font></div><div><font face="monospace, monospace">internal struct Foo {}</font></div></div><div><br></div><div>What do you think?</div></div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>