<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=""><br class=""><div><blockquote type="cite" class=""><div class="">Am 11.08.2016 um 04:58 schrieb Cao, Jiannan via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><span style="font-family: 'PingFang SC';" class="">It is no a mistake. since </span><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0);" class="">fn1: (A</span><span class="pl-k" style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">|</span><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0);" class="">B)</span><span class="pl-k" style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void </span><span style="font-size: 10.5pt; font-family: 'PingFang SC';" class="">is subtype of fn0: </span><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0);" class="">A</span><span class="pl-k" style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void</span><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""> </span></div></div></div></blockquote><div><br class=""></div>That is correct as (A|B) is a supertype of A and it occurs in a contravariant position (argument position) of the funcion type, so (A|B) -> Void is a subtype of A -> Void.</div><div><br class=""></div><div>The current version of the proposal (<a href="https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md#detailed-design" class="">https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md#detailed-design</a>) seems to have been changed, though, as it has it the other way round (i.e. fn1 = fn0).</div><div><br class=""></div><div>-Thorsten</div><div><br class=""><blockquote type="cite" class=""><div class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div id="isForwardContent" class=""><div style="line-height: 1.7; font-size: 14px; font-family: Arial;" class=""><div class=""><div style="font-family: 'PingFang SC';" class=""><br class=""></div><div style="font-family: 'PingFang SC';" class=""><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class="">Detail explain:</span></div><div style="font-family: 'PingFang SC';" class=""><br class=""></div><div style="font-family: 'PingFang SC';" class=""><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">var</span> <span style="background-color: rgba(255, 255, 255, 0);" class="">fn0: A</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void</span> <span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span> <span style="background-color: rgba(255, 255, 255, 0);" class="">{</span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">print</span><span style="background-color: rgba(255, 255, 255, 0);" class="">($0)} </span></div></div><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">var</span> <span style="background-color: rgba(255, 255, 255, 0);" class="">fn1: (A</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">|</span><span style="background-color: rgba(255, 255, 255, 0);" class="">B)</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void</span> <span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span> <span style="background-color: rgba(255, 255, 255, 0);" class="">{</span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">print</span><span style="background-color: rgba(255, 255, 255, 0);" class="">(v0)} </span></div><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">let a = A()</span></div><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">let b = B()</span></div><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">So:</span></div><div style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class=""><br class=""></div><div style="font-family: 'PingFang SC';" class=""><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class="">fn0( a ) // this is OK </span></div><div style="font-family: 'PingFang SC';" class=""><span style="font-size: 10.5pt; font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class="">fn1( a ) // this is also OK</span></div><div style="font-family: 'PingFang SC';" class=""><br class=""></div><div style="font-family: 'PingFang SC';" class=""><span style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif;" class="">fn1 is subtype of fn0, because </span><span style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; font-size: 10.5pt;" class="">fn1 can do anything fn0 do.</span></div><div style="font-family: 'PingFang SC';" class=""><span style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; font-size: 10.5pt;" class="">Thus fn0 = fn1 is OK.</span></div><div style="font-family: 'PingFang SC';" class=""><span style="font-family: Helvetica, Tahoma, Arial, PingFang, 苹方, 'Hiragino Sans GB', 冬青黑体, 'Microsoft YaHei', 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif; font-size: 10.5pt;" class=""><br class=""></span></div><div style="font-family: 'PingFang SC';" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">But:</font></div><div style="font-family: 'PingFang SC';" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class=""><br class=""></font></div><div style="font-family: 'PingFang SC';" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">fn1( b ) // this is OK</font></div><div style="font-family: 'PingFang SC';" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">fn0( b ) // this is not OK</font></div><div style="font-family: 'PingFang SC';" class=""><br class=""></div><div style="font-family: 'PingFang SC';" class=""><font face="Helvetica, Tahoma, Arial, PingFang, 苹方, Hiragino Sans GB, 冬青黑体, Microsoft YaHei, 微软雅黑, SimSun, 宋体, STXihei, 华文细黑, Heiti, 黑体, sans-serif" class="">So fn0 is not subtype of fn1</font></div></div><div style="position:relative;zoom:1" class=""></div><div class=""></div><div class=""><br class=""></div>At 2016-08-11 10:41:02, "Step C" <<a href="mailto:schristopher@bignerdranch.com" class="">schristopher@bignerdranch.com</a>> wrote:<br class=""> <blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid" class=""><div class=""></div><div class="">Shouldn't it be "fn1 = fn0"? Same for the fn2 statements. </div><div class=""><br class=""></div><div class="">`<span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">var</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn0: A</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> </span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> {</span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">print</span><span style="background-color: rgba(255, 255, 255, 0);" class="">(v0)} </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""></span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">var</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn1: (A</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">|</span><span style="background-color: rgba(255, 255, 255, 0);" class="">B)</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> </span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> {</span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">print</span><span style="background-color: rgba(255, 255, 255, 0);" class="">(v0)} </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn0 </span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn1 </span><span class="pl-c" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">// OK, because Original Type and Union Type has a sub-typing relationship</span><span style="background-color: rgba(255, 255, 255, 0);" class="">
</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">var</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class="">fn2: (A</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">|</span><span style="background-color: rgba(255, 255, 255, 0);" class="">B</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">|</span><span style="background-color: rgba(255, 255, 255, 0);" class="">C)</span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">-></span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">Void</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> </span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> {</span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">print</span><span style="background-color: rgba(255, 255, 255, 0);" class="">($</span><span class="pl-c1" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">0</span><span style="background-color: rgba(255, 255, 255, 0);" class="">)} </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""><br class=""></span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn0 </span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn2 </span><span class="pl-c" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">// OK</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> </span></div><div class=""><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn1 </span><span class="pl-k" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">=</span><span style="background-color: rgba(255, 255, 255, 0);" class=""> fn2 </span><span class="pl-c" style="background-color: rgba(255, 255, 255, 0); box-sizing: border-box;">// OK`</span></div><div class=""><br class="">On Aug 10, 2016, at 9:28 PM, Cao Jiannan via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">Hi all,</div><div class=""><br class=""></div><div class="">I want to make a discussion about union type for swift 4.</div><div class="">See <a href="https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md" class="">https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md</a></div><div class=""><br class=""></div><div class=""><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Add union type grammar, represents the type which is one of other types.</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; 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;" class=""><span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">var</span> stringOrURL: <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);">|</span> URL <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">=</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><a href="https://www.apple.com/" class="">https://www.apple.com</a><span class="pl-pds" style="box-sizing: border-box;">"</span></span></pre></div><div class=""><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Now, if we using the new union type feature, we can declare type conveniently, No other type declaration, and compiler will automatically calculate the common interface.</p><div class="highlight highlight-source-swift" style="box-sizing: border-box; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);"><pre style="box-sizing: border-box; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.600000381469727px; 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;" class=""><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);">input</span>(value: A <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">|</span> B <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">|</span> C) {
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(value<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>commonProperty) <span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// type checker will calculate the common interface, developer just use it out of box</span>
<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">switch</span> value {
<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);">let</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">as</span> A:
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// value is type A</span>
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(value<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>propertyInA)
<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);">let</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">as</span> B:
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// value is type B</span>
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(value<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>propertyInB)
<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);">let</span> value <span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">as</span> C:
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// value is type C</span>
<span class="pl-c1" style="box-sizing: border-box; color: rgb(0, 134, 179);">print</span>(value<span class="pl-k" style="box-sizing: border-box; color: rgb(167, 29, 93);">.</span>propertyInC)
}
<span class="pl-c" style="box-sizing: border-box; color: rgb(150, 152, 150);">// there is no default case other than A, B or C. we already declared that.</span>
}</pre></div><p style="box-sizing: border-box; margin-top: 0px; margin-bottom: 16px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255);" class="">Note: A, B, C can be either class or protocol, or any other types. This leaves developer more freedom.</p><div class=""><br class=""></div><div class=""><h2 style="box-sizing: border-box; margin-top: 24px; margin-bottom: 16px; line-height: 1.25; 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: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class="">Impact on existing code</h2><ul style="box-sizing: border-box; padding-left: 2em; margin-top: 0px; color: rgb(51, 51, 51); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 16px; background-color: rgb(255, 255, 255); margin-bottom: 0px !important;" class=""><li style="box-sizing: border-box;" class="">This is a new feature, developer who need declare common type will alter to this new grammar.</li><li style="box-sizing: border-box; margin-top: 0.25em;" class="">Enum based version optional or IUO will be replaced by Union-based ones. Any optional type will automatically replaced by union type</li></ul><div class=""><br class=""></div></div><h2 style="box-sizing: border-box; margin-top: 24px; margin-bottom: 16px; line-height: 1.25; 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: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; background-color: rgb(255, 255, 255);" class=""><a id="user-content-detailed-design" class="anchor" href="https://github.com/frogcjn/swift-evolution/blob/master/proposals/xxxx-union-type.md#detailed-design" aria-hidden="true" style="box-sizing: border-box; background-color: transparent; -webkit-text-decoration-skip: objects; color: rgb(64, 120, 192); text-decoration: none; float: left; padding-right: 4px; margin-left: -20px; line-height: 1;"></a></h2></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote></blockquote></div><br class=""><br class=""><span title="neteasefooter" class=""><div class=""> <br class="webkit-block-placeholder"></div></span></div></div><br class=""><br class=""><span title="neteasefooter" class=""><div class=""> <br class="webkit-block-placeholder"></div></span>_______________________________________________<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>