<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="">On Mar 14, 2017, at 2:13 AM, Dimitri Racordon &lt;<a href="mailto:Dimitri.Racordon@unige.ch" class="">Dimitri.Racordon@unige.ch</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">

<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252" class="">

<div dir="auto" class="">
<div class=""></div>
<div class="">Thanks a lot for your very detailed explanations!</div>
<div class=""><br class="">
</div>
<div class="">So my only issue regarding #1 #2 and #3 is the error message, which really doesn't suggest the actual underlying problem.</div>
<div class=""><br class="">
</div>
<div class="">Regarding #5 and #6, I still feel like the compiler should complain about it. I disagree on the fact that it shouldn't be it's role to disallow uninitializable code, unless using unsafe techniques. This imho isn't consistent with some other errors the
 compiler does emit for ill-defined types.</div></div></div></blockquote><div><br class=""></div>That’s the thing though, they aren’t ill-defined. Just because a type cannot be initialized does not mean it is not useful.</div><div><br class=""></div><div><b class="">1. Namespacing</b></div><div><br class=""></div><div>I admit this is a kind of hacky use, but there’s not better way right now.</div><div><br class=""></div><div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">enum</span> Geometry {</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: #c900a4" class="">struct</span> Point {</div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c900a4" class="">var</span> x: <span style="color: #790ead" class="">Int</span></div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c900a4" class="">var</span> y: <span style="color: #790ead" class="">Int</span></div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">let</span> p <span style="color: #c800a4" class="">=</span> Geometry<span style="color: #c800a4" class="">.</span>Point(x: <span style="color: #3a00dc" class="">0</span>, y: <span style="color: #3a00dc" class="">0</span>)</div></div><div><br class=""></div><div><br class=""></div><div><b class="">2. Uninhabited Types</b></div><div><br class=""></div><div>Swift uses `Never` as the return types of functions that can never return (e.g. `fatalError`). Since `never` is an enum with no cases, it is not possible to construct one. This indicates to the type system that the function will not return.</div><div><br class=""></div><div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">func</span> runloop() <span style="color: #c800a4" class="">-&gt;</span> Never {</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo; color: rgb(200, 0, 164);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span>while<span style="color: #000000" class=""> </span>true<span style="color: #000000" class=""> {</span></div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo; color: rgb(223, 0, 2);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span style="color: #450084" class="">print</span><span style="color: #000000" class="">(</span>"Hello again!"<span style="color: #000000" class="">)</span></div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">let</span> result: Never <span style="color: #c800a4" class="">=</span> runloop()</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; color: rgb(0, 142, 0);" class="">// Since a `Never` type cannot be constructed,</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; color: rgb(0, 142, 0);" class="">// we will not pass this line.</div></div><div><br class=""></div><div><br class=""></div><div><b class="">3. Phantom Types</b></div><div><b class=""><br class=""></b></div><div>Sometimes an uninhabited type is useful for providing information in the type system without creating an instance of the type itself. These tags can be used to provide additional behavior to the type or to provide additional type safety. Here’s another&nbsp;<a href="https://gist.github.com/JadenGeller/f39130616846f9bf9879" class="">example</a>&nbsp;and some&nbsp;<a href="https://wiki.haskell.org/Phantom_type" class="">reading</a>.</div><div><br class=""></div><div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">enum</span> Unvalidated { }</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">enum</span> Validated { }</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">struct</span> User<span style="color: #c800a4" class="">&lt;</span>V<span style="color: #c800a4" class="">&gt;</span> {</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: #c800a4" class="">private</span>(<span style="color: #c800a4" class="">set</span>) <span style="color: #c900a4" class="">var</span> name: <span style="color: #790ead" class="">String</span></div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: #c800a4" class="">private</span>(<span style="color: #c800a4" class="">set</span>) <span style="color: #c900a4" class="">var</span> age: <span style="color: #790ead" class="">Int</span></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">extension</span> User <span style="color: #c800a4" class="">where</span> V <span style="color: #c800a4" class="">==</span> Unvalidated {</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: #c800a4" class="">init</span>(name: <span style="color: #790ead" class="">String</span>, age: <span style="color: #790ead" class="">Int</span>) {</div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">self.</span>name <span style="color: #c800a4" class="">=</span> name</div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">self.</span>age <span style="color: #c800a4" class="">=</span> age</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><p style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo; min-height: 16px;" class="">&nbsp;&nbsp; &nbsp;<br class="webkit-block-placeholder"></p><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="color: #c900a4" class="">func</span> validated() <span style="color: #c800a4" class="">-&gt;</span> User&lt;Validated&gt;? {</div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">guard</span> age <span style="color: #c800a4" class="">&gt;</span> <span style="color: #3a00dc" class="">18</span> <span style="color: #c800a4" class="">else</span> { <span style="color: #c800a4" class="">return</span> <span style="color: #c800a4" class="">nil</span> }</div><div style="margin: 0px 0px 0px 101.1px; text-indent: -101.2px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c800a4" class="">return</span> User<span style="color: #c800a4" class="">&lt;</span>Validated<span style="color: #c800a4" class="">&gt;</span>(name: name, age: age)</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c900a4" class="">func</span> register(_ user: User<span style="color: #c800a4" class="">&lt;</span>Validated<span style="color: #c800a4" class="">&gt;</span>) {</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo; color: rgb(223, 0, 2);" class=""><span style="color: #000000" class="">&nbsp; &nbsp; </span><span style="color: #450084" class="">print</span><span style="color: #000000" class="">(</span>"\(user<span style="color: #c800a4" class="">.</span>name) is registered!"<span style="color: #000000" class="">)</span></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">}</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo; min-height: 16px;" class=""><br class=""></div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class=""><span style="color: #c800a4" class="">if</span> <span style="color: #c900a4" class="">let</span> me <span style="color: #c800a4" class="">=</span> User<span style="color: #c800a4" class="">&lt;</span>Unvalidated<span style="color: #c800a4" class="">&gt;</span>(name: <span style="color: #df0002" class="">"Jaden Geller"</span>, age: <span style="color: #3a00dc" class="">21</span>)<span style="color: #c800a4" class="">.</span>validated() {</div><div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; register(me)</div><div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">}</div><div class=""><br class=""></div></div><div>Cheers,</div><div>Jaden Geller</div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="auto" class=""><div class="">
On 13 Mar 2017, at 22:20, Jaden Geller &lt;<a href="mailto:jaden.geller@gmail.com" class="">jaden.geller@gmail.com</a>&gt; wrote:<br class="">
<br class="">
</div>
<blockquote type="cite" class="">
<div class="">Comments inline:
<div class=""><br class="">
<div class="">
<blockquote type="cite" class="">
<div class="">On Mar 13, 2017, at 6:38 AM, Dimitri Racordon via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
Hello swift-evolution,
<div class=""><br class="">
</div>
<div class="">I noticed there’s some inconsistencies with recursive types and how the compiler handles them. Consider the following cases:</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
</div>
<div class=""><b class="">1.&nbsp;<span style="font-family: Menlo; font-size: 11px; font-variant-ligatures: no-common-ligatures;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Swift is right to refuse compiling this, since there’s no way
 to initialise an instance of `</span>First<span style="font-family: Helvetica; font-size: 12px;" class="">&nbsp;`:</span></span></b></div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> First {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp;&nbsp;<span style="color: rgb(186, 45, 162); font-variant-ligatures: no-common-ligatures;" class="">let</span><span style="font-variant-ligatures: no-common-ligatures;" class="">&nbsp;</span>item:&nbsp;</span>First</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<div style="margin: 0px; line-height: normal; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">// Error: Value type 'First' cannot have a stored property that references itself</span></div>
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<br class="">
</div>
<div style="margin: 0px; line-height: normal;" class="">However, the message suggests more a compiler limitation rather than the actual impossibility to initialize the declared type.</div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">This is a compiler limitation that isn’t going to go away. Structs are value types whose size is equal to the sum of their property sizes. Here, we have a circular dependency, so it is impossible to compute the size.</div>
<div class=""><br class="">
</div>
<div class="">This is not an arbitrary restriction. Consider:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">
<span style="color: #c900a4" class="">struct</span> List<span style="color: #c800a4" class="">&lt;</span>T<span style="color: #c800a4" class="">&gt;</span> {</div>
<div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">
&nbsp; &nbsp; <span style="color: #c900a4" class="">var</span> head: T</div>
<div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">
&nbsp; &nbsp; <span style="color: #c900a4" class="">var</span> tail: List<span style="color: #c800a4" class="">&lt;</span>T<span style="color: #c800a4" class="">&gt;</span>?</div>
<div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">
}</div>
</div>
<div class=""><br class="">
</div>
<div class="">The size of `List` is infinite! Every `Optional&lt;T&gt;` must be big enough to store the type `T` in case the value is not `nil`. Thus, `List` must be big enough to store a `T` AND another list (of the same size):</div>
<div class=""><br class="">
</div>
<div class="">size(of: List&lt;T&gt;) = size(of: T) + size(of: List&lt;T&gt;)</div>
<div class=""><br class="">
</div>
<div class="">It’s easy to see that, assuming `size(of: T)` is non-zero, it is impossible to satisfy this constraint. Yes, Swift could special case the case where there are no other members, but this would be entirely useless (you can’t store state) and would considerably
 muck up the semantics.</div>
<div class=""><br class="">
</div>
<div class="">Note that enums allow members to be marked `indirect`. This would be a reasonable feature for Swift to eventually support for structs as well. In this case, the indirect member would be the size of a pointer, so the size would be statically known and satisfied.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class=""></div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class=""><b class="">2. Swift is also right not to compile this, but the error messages are even less insightful:</b></div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> First {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> item:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Second</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""><span style="color: rgb(0, 132, 0);" class="">// Error: Value type 'First' cannot have a stored property that references itself</span></span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class="">
</div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Second {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> item:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">First</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font color="#008400" face="Menlo" class=""><span style="font-size: 11px;" class="">// Error: Value type&nbsp;</span></font><span style="color: rgb(0, 132, 0); font-family: Menlo; font-size: 11px;" class="">'</span><font color="#008400" face="Menlo" class=""><span style="font-size: 11px;" class="">Second'
 cannot have a stored property that references itself</span></font></span></div>
<div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
</div>
<div style="margin: 0px; line-height: normal;" class="">The problem isn’t that the value types reference
<i class="">themselves</i>. Instead, the problem is that there’s a cyclic dependency between `First` and `Second` that makes it impossible for neither of these structures to be instantiated.</div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">This is an identical problem to #1. The error message could probably be improved. This isn’t a “reference” in the sense of a pointer, but in the sense that there is literally a dependency.&nbsp;</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class=""></div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class=""><b class="">3. Swift should let me do that:</b></div>
<div style="margin: 0px; line-height: normal;" class=""><br class="">
</div>
<div style="margin: 0px; line-height: normal;" class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> First {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> item:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">First</span><span style="font-variant-ligatures: no-common-ligatures" class="">?</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
<div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div class="">The compiler prevents me to declare the above struct, even if there actually is a way to initialise an instance of `First` (e.g. `First(item: nil)`). The message is identical to that of case #1 (maybe it actually
<i class="">is</i>&nbsp;a compiler limitation after all?)</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">This is an identical problem to #1. An option does *not* introduce any indirection. Swift will however allow the following:</div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">
<span style="color: #c900a4" class="">struct</span> First {</div>
<div style="margin: 0px 0px 0px 67.4px; text-indent: -67.5px; line-height: normal; font-family: Menlo;" class="">
&nbsp; &nbsp; <span style="color: #c900a4" class="">let</span> item: [First]</div>
<div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; line-height: normal; font-family: Menlo;" class="">
}</div>
<div style="margin: 0px 0px 0px 33.7px; text-indent: -33.8px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;" class="">
<br class="">
</div>
</div>
<div class="">This is because `Array&lt;T&gt;`—if you look at its declaration—does not *directly* store any type `T`. Instead, it stores a pointer to a buffer holding `T`s, allocated at runtime. These semantics may be a big confusing at first, but this is the tradeoff for
 the better performance value types can sometimes bring.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div class=""></div>
<div class=""><br class="">
</div>
<div class=""><b class="">4. Swift shouldn’t compile this:</b></div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">class</span><span style="font-variant-ligatures: no-common-ligatures" class=""> First {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> item:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">First</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">init</span><span style="font-variant-ligatures: no-common-ligatures" class="">(item:
</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">First</span><span style="font-variant-ligatures: no-common-ligatures" class="">) {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; </span>
<span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">self</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">item</span><span style="font-variant-ligatures: no-common-ligatures" class="">
 = item</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
<div class="">Like in case #1, there’s no way to instantiate `First`. The fact that it’s a reference rather than a value doesn’t change the problem.</div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">This is not a bug IMO. It is not the compiler’s job to prevent you from compiling code that includes a type that cannot be instantiated.</div>
<div class=""><br class="">
</div>
<div class="">Unlike the previous cases, the compiler actually *can* generate code for these types. You _could_ even unsafely instantiate these types. In the previous cases, the compiler could not compute the size of the types.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div class=""></div>
<div class=""><br class="">
</div>
<div class=""><b class="">5. Similarly to case #4, Swift shouldn’t compile this:</b></div>
<div class=""><br class="">
</div>
<div class="">
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(186, 45, 162);" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">indirect</span><span style="font-variant-ligatures: no-common-ligatures;" class="">
</span><span style="font-variant-ligatures: no-common-ligatures" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> First {</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; </span><span style="font-variant-ligatures: no-common-ligatures; color: #ba2da2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> item(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">First</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div>
<div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class="">
<span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div>
</div>
<div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class="">
</span></div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Ditto #4.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span></div>
<div class=""><br class="">
</div>
<div class=""><b class="">6. Cases #4 #5 could be written like case #2, and should also raise compilation errors.</b></div>
<div class=""><br class="">
</div>
</div>
</div>
</div>
</blockquote>
<div class=""><br class="">
</div>
<div class="">Ditto #4.</div>
<br class="">
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div class=""></div>
<div class=""><br class="">
</div>
<div class="">Does someone know if these issues have already been discussed and/or addressed?</div>
<div class=""><br class="">
</div>
<div class="">Thanks,</div>
<div class="">Dimitri Racordon</div>
</div>
</div>
</div>
</blockquote>
<blockquote type="cite" class="">
<div class="">
<div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">
<div style="margin: 0px; line-height: normal;" class="">
<div class=""><br class="">
</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="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</div>
</blockquote>
</div>
<br class="">
</div>
<div class=""><br class="">
</div>
<div class="">I hope I was able to clear up your confusion. Let me know if you have any other questions.</div>
<div class=""><br class="">
</div>
<div class="">Cheers,</div>
<div class="">Jaden Geller</div>
<div class=""><br class="">
</div>
</div>
</blockquote>
</div>

</div></blockquote></div><br class=""></body></html>