Details
-
Type:
Bug
-
Status: Open
-
Priority:
Medium
-
Resolution: Unresolved
-
Component/s: Compiler
-
Labels:
-
Radar URL:
Description
Users report their app is crashing due to a use-after-free when modifying a nonmutating property defined on a protocol extension. Test case project here:
https://github.com/iZettle/Flow/issues/34#issuecomment-429515408
They note that a snapshot compiler with asserts on hits an assertion failure:
https://github.com/iZettle/Flow/issues/34#issuecomment-424802558
The problem occurs when a property defined in a protocol or protocol extension with a nonmutating setter is mutated indirectly, as in:
import CoreGraphics protocol SomeProtocol { } class SomeClass: SomeProtocol { } extension SomeProtocol { var someGetter: CGPoint { nonmutating set { _ = self } get { return .zero } } } SomeClass().someGetter.x = 42 // releases SomeClass() too early
The problem can be worked around by separating the `get` and `set` of the nonmutating property into their own statements:
let someObject = SomeClass() var temp = someObject.someGetter // first get the property temp.x = 42 // update the value someObject.someGetter = temp // then set the property