struct X {
var a: Int
public init() {
if (false) {
a = 2
}
}
}
This is because the check for the initialisation of all variables is insufficient. It does not check variable initialisation in nested function calls, does not do CFA, etc. A proper solution is out of scope for this project.
For now the suggested workaround is to separate the initialisers into two parts – variable declarations and the rest of the code.
public init() {
// variable initialisation
self.x = 3
// rest of the code
self.someFuncUsing(x: self.x)
}
Before the first function call, or the end of the initialiser (whichever comes first), all variables should be initialised.
(Result of #30)
Currently, this is valid code:
This is because the check for the initialisation of all variables is insufficient. It does not check variable initialisation in nested function calls, does not do CFA, etc. A proper solution is out of scope for this project.
For now the suggested workaround is to separate the initialisers into two parts – variable declarations and the rest of the code.
Before the first function call, or the end of the initialiser (whichever comes first), all variables should be initialised.