[swift-evolution] Allowing mutable members in structs

Adrian Kashivskyy adrian.kashivskyy at me.com
Fri Mar 11 05:45:08 CST 2016


I agree with Radek, -1 on this.


Pozdrawiam – Regards,
Adrian Kashivskyy

> Wiadomość napisana przez Radosław Pietruszewski via swift-evolution <swift-evolution at swift.org> w dniu 11.03.2016, o godz. 12:26:
> 
>> Would it make sense to allow mutable properties in structs, which could be mutated even by non-mutating methods?
> 
> This would break the whole mutability model of structs. The whole idea is: structs are always immutable, and you can mark things as “mutable”, but this can only happen if a struct is assigned to a mutable variable.
> 
> — Radek
> 
>> On 11 Mar 2016, at 11:38, Dan Raviv via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> Would it make sense to allow mutable properties in structs, which could be mutated even by non-mutating methods?
>> 
>> I've noticed this could be useful when implementing a non-mutating protocol method. The method semantically doesn't change the state of the protocol's implementor, and therefore shouldn't be declared as mutating. However, *some* implementations might need to change some internal state for implementing the functionality. Making specific struct properties mutable for such a case could make sense.
>> 
>> Alternatively, Swift could allow implementing a non-mutating protocol method as a mutating method in the implementor. Currently, this doesn't seem to be  allowed; Swift doesn't recognize the mutating method as a match for the non-mutating protocol method.
>> 
>> Cheers,
>> Dan
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160311/bc03588e/attachment.html>


More information about the swift-evolution mailing list