Avoid a "variable was written to, but never read" without unnecessary read statements

The deal with withExtendedLifetime is that, x is guaranteed to be alive until the body completes its execution, even if body does not use x at all.

Now, what we want is that c is alive until completion is called. So we want to have withExtendedLifetime(c) { ... }, but we also want to mutate c to nil.

Since the x parameter is read-only, setting nil inside the body will violate the exclusivity rule:

withExtendedLifetime(c) {
  // Don't do this.
  c = nil 
}

we instead mutate c after withExtendedLifetime.

Honestly, I don't know.

1 Like