Crash when using a mutating func in init
Encountered while working on asset traits in our fork.
E.g.
struct S {
var rawValue: Int
init(unsafeRawValue: Int) {
setRawValue(unsafeRawValue)
}
mutating func setRawValue(value: Int) -> Int {
rawValue = value
return rawValue
}
}
This should output a meaningful error message (assuming IR really cannot be output in this case?) instead of crashing the compiler completely.
I did a little investigation. If we want to stay consistent with Swift, then we need to enforce that all properties are initialised:
It does seem like mutating functions can be called from the initialiser and that we can set properties like one would expect.
Another thing (and I think flint has this) is to generate an initialiser with all uninitialised properties if one is not present
Ultimately I think we should treat init as if it was mutable. It's a function that's always run after memory is allocated and before control is handed back to the enclosing scope which may bind it to a let/immutable identifier. Prior to this handover we should be free to mutate it.