<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Prefacing the below with a “I am well-aware this proposal likely won’t make it into Swift 3”:</div><div class=""><br class=""></div><div class="">A feature like this would be nice to use, but before I could get behind any proposal along these lines it I’d want to see it include an explicit strategy for disambiguation.</div><div class=""><br class=""></div><div class="">EG: in your example, your generic subscript uses `self[key]`, and presumably expects that to use the “original” subscript…and not the generic subscript being defined.</div><div class=""><br class=""></div><div class="">I think that’s reasonable in that specific case, but it doesn’t seem unreasonable to anticipate this proposal introducing ambiguities that would need explicit disambiguation…and for which explicit type annotation may not always be adequate to resolve (I could be wrong here, though). </div><div class=""><br class=""></div><div class="">This would need addressing (either showing they won’t be an issue, or providing a reliable disambiguation mechanism).</div><div class=""><br class=""></div><div class="">Relatedly, in-re: “rethrows”: if the syntax supported it, this kind of thing would be another way of tackling the "JSON problem":</div><div class=""><br class=""></div><div class=""> subscript<T>(key: Key, transform: (Value) throws -> T) rethrows -> T {</div><div class=""> guard let value = self[key] else { throw JSON.MissingKey(…) }</div><div class=""> return try transform(value)</div><div class=""> }</div><div class=""><br class=""></div><div class="">…so that e.g. you can write typical parsing-code as</div><div class=""><br class=""></div><div class=""> let asUserID = UserID.init(untrustedString:) // <- assume this is a "throwing constructor"</div><div class=""> let sender = try json[“sender”,asUserID] </div><div class=""> let recipient = try json[“recipient”,asUserID]</div><div class=""><br class=""></div><div class="">…(modulo any syntax errors, etc.), which would benefit from a `rethrows` declaration.</div><div class=""><br class=""></div><div class="">That’s my 2c; thankfully (IMHO) there’s clearly a lot of time for this proposal to simmer.</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Jun 20, 2016, at 1:10 PM, Robert Widmann via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Good morning all. Attached is the proposal Harlan Haskins and I will be submitting shortly about adding generic and `throw`ing subscript declarations to the language. <div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">~Robert Widmann<br class=""><div class=""><br class=""></div><div class=""><h1 class="" style="box-sizing: border-box; font-size: 2.25em; margin-right: 0px; margin-bottom: 16px; margin-left: 0px; line-height: 1.2; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; margin-top: 0px !important;">Generic and Throwing Subscripts</h1><ul class="" style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;"><li class="" style="box-sizing: border-box;">Proposal: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/NNNN-name.md" class="" style="box-sizing: border-box; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;">SE-NNNN</a></li><li class="" style="box-sizing: border-box;">Author(s): <a href="https://github.com/harlanhaskins" class="" style="box-sizing: border-box; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;">Harlan Haskins</a> and <a href="https://github.com/codafi" class="" style="box-sizing: border-box; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;">Robert Widmann</a></li><li class="" style="box-sizing: border-box;">Status: <span class="" style="box-sizing: border-box;"><a href="https://github.com/typelift/SwiftCheck/pull/168#rationale" class="" style="box-sizing: border-box; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none;">Awaiting review</a></span></li><li class="" style="box-sizing: border-box;">Review manager: TBD</li></ul><h2 class="" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';">Introduction</h2><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">Currently, subscripts cannot be declared <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">[re]throws</code> and cannot declare new generic parameters.<br class="" style="box-sizing: border-box;">There isn't a clear reason why they aren't as capable as full-fledged functions, so we propose<br class="" style="box-sizing: border-box;">adding generic constraints and throwing semantics to subscripts.</p><h2 class="" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';">Motivation</h2><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">On the throwing side, currently there are two ways to express a failing subscript:</p><ul class="" style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;"><li class="" style="box-sizing: border-box;">Return an <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">Optional</code>, failing with <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">nil</code>.</li><li class="" style="box-sizing: border-box;">Call <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">fatalError(_:)</code> on failure.</li></ul><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">Both of these throw out useful information about the cause of the underlying error that using Swift's error handling mechanism can otherwise provide.</p><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">As for generics, to take an example, it has become a common pattern among JSON decoding DSL libraries to express a throwing generic extension on <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">Dictionary</code> like so</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; overflow: visible !important;"><pre class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;"><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Dictionary</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">func</span> <span class="pl-en" style="box-sizing: border-box; color: rgb(121, 93, 163);">parse</span><T>(key: Key) throws <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> T {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">guard</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span>[key] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">else</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">throw</span> JSONError<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>MissingKey(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">key</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span>)
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">guard</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> ofType <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">as?</span> T <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">else</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">throw</span> JSONError<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>InvalidKey(key: <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">key</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span>, expectedType: T<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span>, foundType: value<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">dynamicType</span>)
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> ofType
}
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">enum</span> JSONError: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">ErrorType</span>, <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">CustomStringConvertible</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> InvalidKey(key: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>, expectedType: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Any</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Type</span>, foundType: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Any</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">Type</span>)
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> MissingKey(<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span>)
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> description: <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">String</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">switch</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>InvalidKey(<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> key, <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> expected, <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> found):
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Invalid key <span class="pl-cce" style="box-sizing: border-box;">\"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">key</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-cce" style="box-sizing: border-box;">\"</span>. Expected value of type <span class="pl-cce" style="box-sizing: border-box;">\"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">expected</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-cce" style="box-sizing: border-box;">\"</span>, found <span class="pl-cce" style="box-sizing: border-box;">\"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">found</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-cce" style="box-sizing: border-box;">\"</span>.<span class="pl-pds" style="box-sizing: border-box;">"</span></span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">case</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>MissingKey(<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> key):
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>Key <span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">key</span><span class="pl-pse" style="box-sizing: border-box;">)</span> not found.<span class="pl-pds" style="box-sizing: border-box;">"</span></span>
}
}
}</pre></div><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">Given this, one can decode JSON with the full support of native type inference and exception handling. But when working with the DSL, one would expect to be able to express this as a subscript on <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">Dictionary</code>, allowing the following:</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; overflow: visible !important;"><pre class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;"><span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">//...</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">extension</span> <span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">Dictionary</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">public</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">subscript</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);"><</span>T<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">></span>(key: Key) <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">throws</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">-></span> T {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">guard</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span>[key] <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">else</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">throw</span> JSONError<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>MissingKey(<span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">key</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span>)
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">guard</span> <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">let</span> ofType <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">as?</span> T <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">else</span> {
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">throw</span> JSONError<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>InvalidKey(key: <span class="pl-s" style="box-sizing: border-box; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span><span class="pl-pse" style="box-sizing: border-box;">\(</span><span class="pl-s1" style="box-sizing: border-box; color: rgb(51, 51, 51);">key</span><span class="pl-pse" style="box-sizing: border-box;">)</span><span class="pl-pds" style="box-sizing: border-box;">"</span></span>, expectedType: T<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">self</span>, foundType: value<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">dynamicType</span>)
}
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">return</span> ofType
}
}</pre></div><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">We believe this is an even more natural way to write these kinds of libraries in Swift and that bringing subscript member declarations up to par with functions is a useful addition to the language as a whole.</p><h2 class="" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';">Proposed solution</h2><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">Add the ability to introduce new generic parameters and mark <code class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; padding: 0.2em 0px; margin: 0px; background-color: rgba(0, 0, 0, 0.0392157); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">throws</code> and <span style="font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; background-color: rgba(0, 0, 0, 0.0392157);" class="">rethrows </span>on subscript members.</p><h2 class="" style="box-sizing: border-box; margin-top: 1em; margin-bottom: 16px; line-height: 1.225; font-size: 1.75em; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';">Detailed design</h2><p class="" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;">This change will modify and add the following productions in the Swift grammar</p><div class="highlight highlight-source-diff" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; overflow: visible !important;"><pre class="" style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 11.899999618530273px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; word-wrap: normal; padding: 16px; overflow: auto; background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-break: normal;">GRAMMAR OF A SUBSCRIPT DECLARATION
subscript-declaration → subscript-head subscript-result code-block
subscript-declaration → subscript-head subscript-result getter-setter-block
subscript-declaration → subscript-head subscript-result getter-setter-keyword-block
<span class="pl-md" style="box-sizing: border-box; background-color: rgb(255, 236, 236); color: rgb(189, 44, 0);">-subscript-head → attributes(opt) declaration-modifiers(opt) subscript parameter-clause</span>
<span class="pl-mi1" style="box-sizing: border-box; background-color: rgb(234, 255, 234); color: rgb(85, 165, 50);">+subscript-head → attributes(opt) declaration-modifiers(opt) generic-parameter-clause(opt) subscript parameter-clause</span>
<span class="pl-mi1" style="box-sizing: border-box; background-color: rgb(234, 255, 234); color: rgb(85, 165, 50);">+subscript-result → -> attributes(opt) throws(opt) type</span>
<span class="pl-mi1" style="box-sizing: border-box; background-color: rgb(234, 255, 234); color: rgb(85, 165, 50);">+subscript-result → -> attributes(opt) rethrows(opt) type</span></pre></div><hr class="" style="box-sizing: content-box; height: 4px; overflow: hidden; margin: 16px 0px; background-color: rgb(231, 231, 231); border: 0px none; padding: 0px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px;"><h1 class="" style="box-sizing: border-box; font-size: 2.25em; margin: 1em 0px 16px; line-height: 1.2; padding-bottom: 0.3em; border-bottom-width: 1px; border-bottom-style: solid; border-bottom-color: rgb(238, 238, 238); color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';">Rationale</h1><div class="" style="box-sizing: border-box; margin-top: 0px; color: rgb(51, 51, 51); font-family: 'Helvetica Neue', Helvetica, 'Segoe UI', Arial, freesans, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; margin-bottom: 0px !important;">On [Date], the core team decided to <span class="" style="box-sizing: border-box;">(TBD)</span> this proposal.<br class="" style="box-sizing: border-box;">When the core team makes a decision regarding this proposal,<br class="" style="box-sizing: border-box;">their rationale for the decision will be written here.</div></div></div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>