<div dir="ltr">I cast a reluctant -1 <div><br></div><div>I&#39;ve followed this thread since its beginning and do believe that this could be a  nice feature but I agree that it doesn&#39;t pay for its own complexity in this proposal. We would be better served if we could spell out what needs to be implemented for the variadics and or the magic Members tuple, in my opinion.</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 7, 2016 at 10:37 PM, Matthew Johnson via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On Jan 7, 2016, at 8:55 PM, Joe Groff via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div style="word-wrap:break-word">The proposal says that &quot;let&quot; properties with inline initializers should be left out of the memberwise initialization, AIUI on the grounds that a manually-written initializer would not be allowed to override the inline initialization:</div></div></blockquote><div><br></div></span><div>Yes, this is because Chris insisted that the proposal be pure sugar for something that could be manually written.  This ensures that anyone using memberwise initialization can stop using it in any case where that becomes necessary. </div><span class=""><br><blockquote type="cite"><div style="word-wrap:break-word"><div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div>class C {</div><div>  let x = 1738</div><div>  init(x: Int = 679) {</div><div>    self.x = x // Error, self.x already initialized</div><div>  }</div><div>}</div><div><br></div></blockquote>However, this is also true for vars. Semantically, if you change &#39;x&#39; to a var in the above example, you get an initialization followed by an assignment:<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div>class C {</div></div><div><div>  let x = dump(1738)</div></div><div><div>  init(x: Int = dump(679)) {</div></div><div><div>    self.x = x</div></div><div><div>  }</div></div><div><div>}</div></div></blockquote><div><br></div><div><span style="white-space:pre-wrap">        </span>    C() // dumps 1738, then 679</div><div><br></div><div>which, if the initialization has side effects, will likely be surprising. We could say that the memberwise initializer elides the inline initialization of `var`s, on the grounds that initializations ought not to have side effects, but then we&#39;re introducing a behavior change in inline initializers for `var`s in the face of `memberwise` initializers that also cannot be replicated by a manually-written initializer. If we make that behavior change for vars, I think it&#39;s reasonable, and more orthogonal, to extend the same grace to lets as well. That also simplifies the rules for what appears in the memberwise initializer—there&#39;s now only two rules (or one, if we also remove the access control filter, as I&#39;ve suggested in another subthread).</div></div></blockquote><br></span></div><div>I agree.  The dual assignment for `var` seems wasteful in addition to potentially surprising and the limitation for `let` is unfortunate.  Of course the same can be said for all initializers that might wish to assign a different value to a `let` or do assign a different value to a `var`.</div><div><br></div><div><div>What you suggest is exactly how I wanted the proposal to work.  Chris was opposed to this approach.  I would be very happy with this change if you can sell Chris on it!  I think many others would be as well. </div><div><br></div><div>In addition to this not being possible to implement manually, Chris explained to me that it is important to the optimizer to be able to assume a `let` with an inline initializer will never have any other value (especially when that inline initializer is a constant value).  Allowing an instance member to be optimized away when initialized with a constant value enables it to be referenced with convenient syntax due to implicit `self`.  It would have never occurred to me to make a true constant value an instance property, but apparently this is a common practice.  And with a guaranteed optimization is makes sense to take advantage of the implicit `self`.  </div><div><br></div><div>At the same time, IMO the inability to provide a default value for a property that is only used when it is not initialized manually is a more important issue.  I wish the “inline initializer” worked this way.  </div><div><br></div><div>I know the implementation would be a bit more complex - the compiler would have to analyze the body of non-memberwise initializers before synthesizing the inline-initialization if necessary.  But it already emits an “uninitialized member” error message so it already knows which properties are initialized and which are not.  That information may not be available in the right part of the compiler but we do not how to determine this.</div><div><br></div><div>This would solve the init / assign problem for `var` and the no overridable default problem for `let` in both existing and memberwise initializers.  It would also mean that memberwise initializers can work this way while still being pure sugar for code that can be written manually.  Unfortunately this seems like something that is not open for change.</div><div><br></div><div>Matthew</div></div><div><br></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=3FGfocPbgxkNkmje7djckg9Iw-2BGYY3X6RxJ1tkUXKCqBSJJ5JlyVI4wnJRL6YhUkOeMH6-2Bd8OhA-2FvfyQoRSAn9FnO21FnN7yK3PGAHgGop7YoOq3k2nIym-2BIxAFhOQYGtDGvWfCgUGojEr4psfxsw3-2FvkyW0norwJDmkn0mlAnrgxw-2FNH2byEfMtez6MY9fLgl1d8P-2FfLxX-2BKVTLxXHS0QfKsantPqu5F707LKAjHy8-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
<br></blockquote></div><br></div>