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

Docs

XO0209: the result of a call that only computes a value is discarded

error · reported by the checker

Values are not changed in place: xs.reverse(), xs.sort(), s.trim(), xs.map(f) and the like return a new value and leave the receiver as it was. As a statement such a call does nothing. XO0209 reports an expression statement whose call performs no effect (section 6), mutates no var receiver or argument, and reaches no handle, interface, or function value through its receiver or arguments (an Atomic.add, a channel receive, or a spawn is not reported). The fix assigns the result back (xs = xs.reverse()) when the receiver is a var binding of the same type; write let _ = f() to discard a result on purpose. A defer statement’s call is not reported, and xo check --wip reports it as a warning while the code is still being written. See core 2.6 and decision 0258.

Example

fn f() -> List[Int] {
  var xs = [3, 1, 2]
  xs.sort()
  xs
}

Fix

fn f() -> List[Int] {
  var xs = [3, 1, 2]
  xs = xs.sort()
  xs
}

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