I have me at a standstill. I cannot understand why Swift complains that self.init is called more than once in this code:
public init(body: String) { let parser = Gravl.Parser() if let node = parser.parse(body) { super.init(document: self, gravlNode: node) } else {
If something is missing for me, it is very obvious that it only calls init once. Oddly enough, if I comment on the second line, Swift complains that Super.init is not called on all paths, lol.
What am I missing?
Update:
Ok, so the problem was definitely trying to pass self in a super.init call. I completely forgot that I do this, ha. I think I wrote it experimentally and got it for compilation and thought it could really work, but it looks like itβs actually a mistake that it compiled in general.
In any case, since passing self to the initializer is redundant, since it is the same object, I changed the parent initializer to accept an optional document parameter (this is just an internal initializer, so it doesn't really matter), and if it is nil I just set it to self in the parent initializer.
For the curious, this looks like a parent initializer (now):
internal init(document: Document?, gravlNode: Gravl.Node) { self.value = gravlNode.value super.init() self.document = document ?? self as! Document
source share