<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">2017-07-10 14:05 GMT+09:00 Xiaodi Wu <span dir="ltr"><<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">This would be very useful, but the spelling needs dramatic improvement.<br><br>"Available unavailable" is already challenging to read, but at least it is learnable with time. The example where "@available(*, deprecated, access: internal) open" means "fileprivate" is entirely unreasonable.<br><br></blockquote><div><br></div><div>I agree, but I couldn't come up with a better spelling.</div><div><br></div><div><font face="monospace, monospace">// "deprecated" if the access is from "outside" of "fileprivate" scope.</font></div><div><font face="monospace, monospace">@available(*, deprecated, outside: fileprivate) </font><span style="font-family:monospace,monospace">open</span></div><div><div><br></div></div><div>Hmm.. 🤔</div><div><br></div><div>Any suggestions will be greatly appreciated!</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><div><div class="gmail-m_465776830666725481m_5773591088566474201gmail-h5"><div dir="ltr">On Sun, Jul 9, 2017 at 22:40 rintaro ishizaki via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="gmail-m_465776830666725481m_5773591088566474201gmail-h5"><div dir="ltr">Hi evolution community,<div><br></div><div>I would like to propose "Scoped @available" 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<wbr>/blob/master/stdlib/public/cor<wbr>e/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'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">"access"</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: "it will be </font><span style="font-family:monospace,monospace">removed</span><font face="monospace, monospace"> in future")<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: 'OldProtocol' 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></div></div>
______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/swift-evolution</a><br>
</blockquote></div>
</blockquote></div><br></div></div>