Clearly many uses for this; would like to see it some day, definitely. However, IIRC, the last day for any _code_ to be incorporated in Swift 4 is June 1. There's simply no chance that this can be considered for the current phase of Swift evolution.<br><br>When it does come into scope (which will depend on the core team's identified priorities), the one thing I would comment is that there is no need for a name such as "undefined": we already have "fatalError()".<br><br><br><div class="gmail_quote"><div dir="ltr">On Sun, May 14, 2017 at 17:27 André Videla via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div style="margin:0px;line-height:normal">Hi Swift-Evolution,</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">At the end of SE-0102 (<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0102-noreturn-bottom-type.md" target="_blank">https://github.com/apple/swift-evolution/blob/master/proposals/0102-noreturn-bottom-type.md</a>) it is mentioned that the Never type could be used as a universal bottom type but that is currently not the case.</div><div style="margin:0px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal">As of today the Never type is used as a return type of `fatalError` and as function which do not return by the virtue of calling `fatalError`.</div><div style="margin:0px;line-height:normal">This allows for very useful behaviours for example:</div><div style="margin:0px;line-height:normal;font-family:Monaco"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> anything: </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">Any</span><span style="font-variant-ligatures:no-common-ligatures"> = …</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">switch</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">anything</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">case</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> view </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">UIView</span><span style="font-variant-ligatures:no-common-ligatures">: …</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">case</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> str </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">as</span><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">String</span><span style="font-variant-ligatures:no-common-ligatures">: …</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">default</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">: </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">fatalError</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">(</span><span style="font-variant-ligatures:no-common-ligatures">"we got an unexpected type"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal">But it has its limits, most notably, it cannot be used as an expression</div><div style="margin:0px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> dunno: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:#3e1e81">fatalError</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b">"what should I put here?"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">) </span><span style="font-variant-ligatures:no-common-ligatures">// cannot convert value of type 'Never'</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div><div style="margin:0px;line-height:normal">It makes sense because Never is not a bottom type. If it were, this statement would be absolutely valid.</div><div style="margin:0px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal">Having a bottom type and a value for it has several advantages:</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal;min-height:14px">- More informative error messages with forced unwrap:</div><div style="margin:0px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">protocol</span><span style="font-variant-ligatures:no-common-ligatures"> WonkyAPI {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> apiCall() -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">Int</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">? </span><span style="font-variant-ligatures:no-common-ligatures">//this always return an Int, why is it optional?</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> mycode() {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> valueFromAPI = apiCall() ?? fatalError(</span><span style="font-variant-ligatures:no-common-ligatures">"The API used to always return a value, but now it does not!"</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> …</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">It sometimes happen that some part of the code uses an optional but in your particular codepath, the optional is always containing a value (for example after an assignment).</div><div style="margin:0px;line-height:normal">As of today, you can write</div><div style="margin:0px;line-height:normal"><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">guard</span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> </span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">let</span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> value = value </span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)">else</span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures"> { fatalError(</span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)">"something terrible happened"</span><span style="font-family:Menlo;font-size:11px;font-variant-ligatures:no-common-ligatures">) }</span></div><div style="margin:0px;line-height:normal">for the same effect with a more verbose syntax.</div><div style="margin:0px;line-height:normal;min-height:14px"><br></div><div style="margin:0px;line-height:normal">- Use as a hole/placeholder during development</div><div style="margin:0px;line-height:normal">During development it is very likely that you will want to write a piece of functionality but be stuck on an intermediate part of the computation. Assume we have an identifier `undefined` of type `Never` which would represent an impossible value as a bottom type. We would ben able to write:</div><div style="margin:0px;line-height:normal;font-family:Monaco;min-height:16px"><br></div><div style="margin:0px;line-height:normal;font-family:Monaco"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> transform(point: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">CGPoint</span><span style="font-variant-ligatures:no-common-ligatures">) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">CGPoint</span><span style="font-variant-ligatures:no-common-ligatures"> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> translation = </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">Matrix3D</span><span style="font-variant-ligatures:no-common-ligatures">(</span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">0</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">2</span><span style="font-variant-ligatures:no-common-ligatures">,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">0</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">-2</span><span style="font-variant-ligatures:no-common-ligatures">,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">0</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">0</span><span style="font-variant-ligatures:no-common-ligatures">, </span><span style="font-variant-ligatures:no-common-ligatures;color:#272ad8">1</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(0,132,0)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> rotation: </span><span style="font-variant-ligatures:no-common-ligatures;color:#4f8187">Matrix3D</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> = </span><span style="font-variant-ligatures:no-common-ligatures;color:#31595d">undefined</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> </span><span style="font-variant-ligatures:no-common-ligatures">//what was it? I forgot</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">return</span><span style="font-variant-ligatures:no-common-ligatures"> (translation * rotation * point.homogenous).toPoint()</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div style="margin:0px;line-height:normal;font-family:Monaco;min-height:16px"><br></div><div style="margin:0px;line-height:normal">We can debate on the right naming for undefined. Haskell uses 'undefined', Scala uses `???`. `unimplemented`, `impossible`, `void`are all valid contenders.</div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal">- Eliminate type annotations for generic covariant types</div><div style="margin:0px;line-height:normal">As of today this is not valid </div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">struct</span><span style="font-variant-ligatures:no-common-ligatures"> Person {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">let</span><span style="font-variant-ligatures:no-common-ligatures"> name: </span><span style="font-variant-ligatures:no-common-ligatures;color:#703daa">String</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">var</span><span style="font-variant-ligatures:no-common-ligatures"> maybeSomeone = </span><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">nil</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures">maybeSomeone</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> = </span><span style="font-variant-ligatures:no-common-ligatures">Person</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">(name: </span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b">"Doug”</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(79,129,135)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"><br></span></div></div><div style="margin:0px;line-height:normal">Even though it is clear that maybeSomeone is of type Optional<Person>.</div><div style="margin:0px;line-height:normal">That is because the compiler cannot guess which type the Optional wraps when `maybeSomeone` is declared. But with a bottom type, a naked nil can be mapped to `Optional<Never>` until the type inference figures out from the context what is the type of Optional. If it cannot because no use or no assignment is done, the compiler could emit an “unreachable” warning just like it does for </div><div style="margin:0px;line-height:normal"><br></div><div style="margin:0px;line-height:normal"><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2">func</span><span style="font-variant-ligatures:no-common-ligatures"> unreach() {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures"> fatalError(</span><span style="font-variant-ligatures:no-common-ligatures;color:#d12f1b">"stop here"</span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(209,47,27)"><span style="font-variant-ligatures:no-common-ligatures;color:#000000"> print(</span><span style="font-variant-ligatures:no-common-ligatures">"not printed”</span><span style="font-variant-ligatures:no-common-ligatures;color:#000000">) // warning: will never be executed</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-variant-ligatures:no-common-ligatures">}</span></div></div><div><br></div><div>Should I write a proposal?</div><div><br></div><div>André Videla</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>