Bug or intended? "thing?.property = something" will trigger didSet observer even if thing is nil, but ONLY IF thing is a struct type

It might be worth noting that while the above program compiles with eg the default toolchain of Xcode 9.3 beta 4, it crashes recent versions of the compiler (for example dev snapshot 2018-02-25, 2018-03-13 and 2018-03-17, have only tested those three).

The following smaller program demonstrates the same issue (crashing recent versions of the compiler, but compiling and running, printing "hello", with eg default toolchain of Xcode 9.3 beta 4):

var a: Int? {
    didSet { print("hello") }
}
a? = 123

Filed SR-7220.

1 Like