Edit: finished, duplicate of Why doesn't this obvious infinite recursion give a compiler warning? I believed that given the many clever warnings Swift has and also the designated initialiser system that it was reasonable to expect a warning, but this is wrong, as explained in the above.
I found this interesting example by playing around with protocol extensions, then realised it screws up structs as well.
struct WhatThe {
let a = 1
init(value: Int) {
self.init()
}
init() {
self.init(0)
}
}
print(WhatThe().a) //nothing is printed and the CPU goes nuts.
This is a bug isn't it? I understand this is an infinite loop, I'm just really surprised Apple allowed this. This code has no warnings and builds fine, Playground even runs it. I feel like this kind of thing was an obvious issue in the language to get rid of. It's fine in classes right?- because these are both convenience initialisers?