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?

Thanks!

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

Reply via email to