You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An idiom used in JSONEncoder is violating Swift's rules about exclusive
access to memory. The 'with(pushedKey:)' family of mutating functions
on EncodingContainers modify 'self' by pushing a key, executing a
passed-in closure, and popping the key. However, when the passed-in closure
refers to 'self' this violates the rules for exclusive access since the
closure reads self while with(pushedKey:) has an already in-progress
modification of 'self'.
return self.with(pushedKey: _JSONKey(index: self.count - 1)) {
// Referring to 'self.codingPath' violates rules for exclusive access.
...
}
The compiler is warning about this. To address these warnings, change
the callback to with(pushKey:) to accept an additional parameter: the
modified encoding container. This enables the closure to safely refer to it
without accessing via the captured `self` and avoids the violation of
exclusive access to memory. This also makes it explicit that in the body the
body of the closure the value of .codingPath read is the mutated one and
not the original.
0 commit comments