[swift-dev] [PITCH] Improve Optional Chain Assignment on Tuple Assignment

Cao, Jiannan frogcjn at 163.com
Sat Dec 16 01:21:12 CST 2017

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?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171216/9cc3109f/attachment.html>

More information about the swift-dev mailing list