Flow: Xcode 10 crashes with ReadWriteSignal

Expected Behavior

The ReadWriteSignal setter should not crash

Current Behavior

ReadWriteSignal crashes when trying to access its setter

Steps to Reproduce

Here is a simple unit test to reproduce the crash

    func testReadWriteSignalCrashing() {
        ReadWriteSignal(CGPoint.zero).value.x = 2 // This one crashes for some reason
    }

Note that these tests are passing:

    func testReadWriteSignalNotCrashing() {
        ReadWriteSignal(CGPoint.zero).value = CGPoint(x: 2, y: 0) // This is fine
        let signal = ReadWriteSignal(CGPoint.zero)
        signal.value.x = 2 // This is also fine
    }

Context

The test fails when building with Xcode 10

Failure Logs

Error: Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 18 (12 by maintainers)

Most upvoted comments

I played a bit with this bug, and this is the minimum of code I could find that reproduces the issue:

protocol SomeProtocol { }
class SomeClass: SomeProtocol { }

extension SomeProtocol {
    var someGetter: CGPoint {
        nonmutating set { _ = self }
        get { return .zero }
    }
}

func testCrashingSetter() {
    SomeClass().someGetter.x = 2
}

I suspect that it has something to do with the nonmutating key-word. I guess the compiler is a bit too agressive since I guess it assumes that the object is safe to be deallocated because it won’t be mutated.