<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 08.01.2016 um 00:41 schrieb Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class="">
<title class=""></title>
<div class=""><div class="">On Thu, Jan 7, 2016, at 03:11 PM, Matthew Johnson wrote:<br class=""></div>
<blockquote type="cite" class=""><div class=""> </div>
<div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 3:31 PM, Kevin Ballard <<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>> wrote:<br class=""></div>
<div class=""> </div>
<div class=""><div class=""><div class="">On Thu, Jan 7, 2016, at 07:12 AM, Matthew Johnson wrote:</div>
<blockquote type="cite" class=""><div class=""><div class="">Do you have an example of where you would want a caller to initialize a property, but then overwrite the value they provide <b class="">during initialization</b>?<br class=""></div>
</div>
</blockquote><div class=""> </div>
<div class="">Sure, how about something like a Rect type that always guarantees it's in "standard" form (e.g. no negative sizes):<br class=""></div>
<div class=""> </div>
<div class="">struct StandardRect {<br class=""></div>
<div class=""> var origin: CGPoint<br class=""></div>
<div class=""> var size: CGSize {<br class=""></div>
<div class=""> didSet {<br class=""></div>
<div class=""> // ensure standardized form here<br class=""></div>
<div class=""> }<br class=""></div>
<div class=""> }<br class=""></div>
<div class=""> </div>
<div class=""> memberwise init(...) {<br class=""></div>
<div class=""> if size.width < 0 {<br class=""></div>
<div class=""> origin.x += size.width<br class=""></div>
<div class=""> size.width = -size.width<br class=""></div>
<div class=""> }<br class=""></div>
<div class=""> if size.height < 0 {<br class=""></div>
<div class=""> origin.y += size.height<br class=""></div>
<div class=""> size.height = -size.height<br class=""></div>
<div class=""> }<br class=""></div>
<div class=""> }<br class=""></div>
<div class="">}<br class=""></div>
</div>
</div>
</blockquote><div class=""> </div>
<div class="">This is a good example. Thanks! <br class=""></div></div></blockquote></div></div></blockquote><div><br class=""></div>Actually I do not like this example for several reasons: (1) I would make the rectangle an immutable type with let properties, (2) the didSet already seems to do what is encoded in the memberwise init, so this seems to be redundant, (3) the memberwise init is so complex that having the automatic initialization feature is not really worth it for this example, especially as it seems to require using var properties instead of let properties to do the overwriting.</div><div><br class=""></div><div> </div><div><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class="">
<div class="">I think cases like this will be rare so I still think a warning is a good idea. Something like -Wno-overwrite-memberwise-init would allow it to be suppressed in cases where you actually do intend to do this. Would that satisfy you?<br class=""></div>
</div>
</blockquote><div class=""> </div>
<div class="">No. It's not appropriate to have the only way to suppress a warning on perfectly legal code to be passing a flag to the swiftc invocation. Especially because we have no precedent yet for even having flags like that.</div>
<div class=""> </div>
<div class="">What's wrong with the suggestion to make the warning behave the same way as dead store warnings (e.g. warn if the property is overwritten without any prior reads)? We already have logic for doing this kind of analysis.<br class=""></div></div></blockquote><div><br class=""></div><div><br class=""></div><div>I think this would not be sufficient, because this would not allow overwriting a property based on the value of another property which might be necessary as well.</div><div>Actually isn’t this what happens in your example? The property origin is overwritten without being read, so this would generate the warning, or did I understand something wrong?</div><div><br class=""></div><div>-Thorsten</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="">
<div class=""> </div>
<div class="">-Kevin Ballard</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspdvG6u5vmS2ZOpuls2gujZKzlZYZoxZVS1mOH7WP1CAvbC1sTX4PfyyjRH-2BBnxjMs0mSXjxy9-2FzBfgcgiCckypVIw7DWX1ioWtKIUzH56GL2sIfPM0VzHOKfQS1-2FJdiH-2FE8TrokUpDl8K1Lkz1tQiQnpzST7KXQd8Y7vPznB7ly2chmYxgqmfbU8TU9lh0Mo-2Fk-3D" alt="" width="1" height="1" border="0" style="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;" class="">
</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>