Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · XO0539

Docs

XO0539: a place assigned twice in one destructuring assignment

error · reported by the checker

(a, b) = v evaluates v, then stores its elements into the places left to right. A place named twice ((a, a), (p.x, p.x), (xs[i], xs[i]), compared by their source text) would keep whichever element is stored last, which is almost always a typo for another place. Name each place once, and use _ for an element to drop. See core 5.2 and decision 0536.

Example

fn f() -> Int {
  var a = 0
  var b = 0
  (a, a) = (1, 2)
  a + b
}

Fix

fn f() -> Int {
  var a = 0
  var b = 0
  (a, b) = (1, 2)
  a + b
}

Run xo explain XO0539 for this text in a terminal, or see section 10.6 of the specification.