Friday, October 12, 2018

Working Around a Swift “nonmutating” Crash

Nataliya Patsovska (via Florent Pillet):

We recently found a mysterious bug in our framework Flow present only when building with Xcode 10:

-Mutating an object on the same line it was created on would cause BAD_ACCESS crash.

-Splitting the line into 2 lines would work fine.

Of course that was a workaround, not the fix.

[…]

Turns out we were using the “nonmutating” keyword in a protocol extension and the compiler decided it is safe to deallocate the object implementing the protocol too early.

Moving the setter to the class somehow worked[…]

See also: Mutating And Nonmutating Functions.

Previously: Exploring Swift Array’s Implementation.

Update (2018-10-15): Joe Groff notes the bug page and a potential fix.

Comments RSS · Twitter

Leave a Comment