<div dir="ltr">Hey Swift team can you tell the iTunes Connect team their website is down, there is no way to get a hold of them.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 10:35 PM, Josh Avant 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 dir="ltr"><div>Currently, when a reference-type adopts a protocol with a function declared as `mutating`, the reference-type&#39;s implementation cannot call that function internally. This is because the compiler enforces an immutable `self` pointer value, and the `mutating` qualifier implies that the function implementation may mutate that `self` pointer value.</div><div><br></div><div>However, there seems to be a number of fairly reasonable situations where a reference-type implementation of these `mutating` functions may only want to mutate properties owned by `self`, but not the actual `self` pointer value.</div><div><br></div><div>Consider this toy example:</div><div><br></div><div>```</div><div>import Foundation</div><div><br></div><div>protocol RandomDataTransformable {</div><div>    typealias TransformableType</div><div>    var data: [TransformableType] { get set }</div><div>    </div><div>    mutating func addRandomData()</div><div>}</div><div><br></div><div>extension RandomDataTransformable where TransformableType == Int {</div><div>    mutating func addRandomData() {</div><div>        let random = Int(arc4random_uniform(6) + 1)</div><div>        data.append(random)</div><div>    }</div><div>}</div><div><br></div><div><br></div><div>/////</div><div><br></div><div>// VALID</div><div>struct NumberSource_Struct : RandomDataTransformable {</div><div>    typealias TransformableType = Int</div><div>    var data: [Int] = []</div><div>    </div><div>    mutating func addData() {</div><div>        addRandomData()</div><div>    }</div><div>}</div><div><br></div><div><br></div><div>// VALID</div><div>class NumberSource_ClassDeclaration: NSObject, RandomDataTransformable {</div><div>    typealias TransformableType = Int</div><div>    var data: [Int] = []</div><div>}</div><div><br></div><div>var numberSource = NumberSource_ClassDeclaration()</div><div>numberSource.addRandomData()</div><div><br></div><div><br></div><div>// INVALID</div><div>class NumberSource_ClassImplementation: NSObject, RandomDataTransformable {</div><div>    typealias TransformableType = Int</div><div>    var data: [Int] = []</div><div>    </div><div>    func addData() {</div><div>        self.addRandomData() // Compiler Error: Cannot use mutating member on immutable value: &#39;self&#39; is immutable</div><div>    }</div><div>}</div><div>```</div><div><br></div><div>Even despite the fact that the default implementation for `addRandomData` does not mutate the `self` pointer value, reference-type implementations are unable to call that function internally, since it is marked as `mutating`.</div><div><br></div><div>Perhaps confusingly, `addRandomData` may be called by externally, by objects which own instances of the reference-type (even though, again, it may not called internally by the implementation, itself).</div><div><br></div><div>Currently, the only solution to allow reference-type implementations to call the sample `addRandomData` implementation internally is to qualify the whole `RandomDataTransformable` protocol as `class`. The downside here is that this takes an otherwise perfectly reference- and struct-compatible protocol + extension implementation and restricts it to only apply to classes, decreasing overall code reusability.</div><div><br></div><div>My proposal would be to introduce an intermediate mutation qualifier that applies when protocols are adopted by reference-types. The qualifier would specify that the `self` pointer value itself may not be mutated, but `self`&#39;s properties may be, as appropriate.</div><div><br></div><div>Thoughts, feedback on this?</div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxEiiG-2B6vobzB3Y51Xkdym-2FStbTz0lFYOGerJ2srDTobDdv-2F-2FMfqX4f9eT6OH-2BtVnPlxfXoknILKhOyBf8k3jVzt6e6FjvMl9tQng3MR9DOy-2BvORvHDOSananAQimkvVjX9T5zej2vLBJ6pIwFbZ7M8d5mNfmK-2BTnUPxMQCrhkihOQtnoe7Dv5IM-2BKJI916eKao-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">
<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><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div>