LeonardoCardoso/InitMacro

Is it possible to apply this macro to a class that has inheritance

insinfo opened this issue · 1 comments

Is it possible to apply this macro to a class that has inheritance, can the macro see all members of all its supertypes to generate the correct constructor/init?

// @Init
// base person
class Person {
    let name: String = ""
    let type: String = "indefined"

    init(name: String, type: String) {
        self.name = name
        self.type = type
    }
}

// @Init
// natural person
class PhysicalPerson: Person {
    let age: Int = 0
    let socialSecurity: String = ""

    init(name: String, age: Int, socialSecurity: String) {
        self.age = age
        self.socialSecurity = socialSecurity
        super.init(name: name, type: "physical")
    }
}
// @Init
// legal person
class JuridicalPerson: Person {
    let dunsNumber: String = ""
}

Hi! Unfortunately, that's not possible right now or maybe will never be possible. This limitation is inherent to Macros; they can only see the scope of the entities they're directly applied to, not those of inherited classes.