Accessing a property of an uninitialized instance results in a Runtime error

Disclaimer: This is a cross post from Accessing a property of an uninitialized instance results in a Runtime error · Issue #70908 · apple/swift · GitHub. I see a lot of open issues there and I doubt this will get noticed anytime soon.

Is this documented behavior?

The code produces a runtime error instead of a compile-time error. I would anticipate this to be an error that could be identified during compile-time.

It's worth mentioning that removing the print and having just instance.x allows the compiled binary to execute without any runtime errors (exit code 0).

Reproduction

class SomeClass {
    let x: Int = 0
}

print(instance.x)
var instance = SomeClass()
1 Like
4 Likes