> On Dec 16, 2017, at 2:21 AM, Cao, Jiannan via swift-dev <swift-dev@swift.org> 
> wrote:
> 
> Hi all,
> 
> I have come up an improvement point about Optional Chain Assignment
> 
> 1. Optional Chain Assignment not working with tuple assignment
> 
> optional chain assignment only work for directly assignment, not working with 
> tuple assignment.
> 
> For example:
> 
> struct ListNode {
>     var next: ListNode?
> }
> 
> var previous: ListNode?
> var current: ListNode? = ListNode()
> 
> //original version
> let temp = current?.next
> current?.next = previous
> previous = current
> current = temp
> 
> // tuple assignment version (currently compiler error)
> (current?.next, previous, current) = (previous, current, current?.next)
> 
> error: cannot assign to immutable expression of type '_?'
> (current?.next, previous, current) = (previous, current, current?.next)
>  ~~~~~~~~~~~~~                     ^
> 
> Should we improve this situation?

Optional chain assignment normally prevents the RHS of the assignment from 
being evaluated if the chain is aborted.  What do you recommend as the 
semantics here?  What if the optional element is later in the sequence?

John.
_______________________________________________
swift-dev mailing list
swift-dev@swift.org
https://lists.swift.org/mailman/listinfo/swift-dev

Reply via email to