I'm trying to do some constructor delegation and I...
# announcements
k
I'm trying to do some constructor delegation and I'm getting the error
There's a cycle in the delegation calls chain
and I'm not quite sure why. Does anyone know how to fix this?
Copy code
internal class EmptyComponentModel private constructor(
    override val countryCode: CountryCode,
    override val saleStatus: SaleStatus,
    override val price: Monetary? = null,
    override val saleNotes: String? = null
) : PlacardComponentModel(ListingSaleType.Unknown) {

    constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
        countryCode = countryCode,
        saleStatus = saleStatus
    )
}
There doesn't seem to be a lot of information about this online that I can find
s
What if you try this:
Copy code
internal class EmptyComponentModel private constructor(
    override val countryCode: CountryCode,
    override val saleStatus: SaleStatus,
    override val price: Monetary? = null,
    override val saleNotes: String? = null
) : PlacardComponentModel(ListingSaleType.Unknown) {

    constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
        countryCode = countryCode,
        saleStatus = saleStatus,
        price = null,
        saleNotes = null
    )
}
k
adding the remaining properties fixes this
Copy code
constructor(countryCode: CountryCode, saleStatus: SaleStatus) : this(
        countryCode = countryCode,
        saleStatus = saleStatus,
        price = null,
        saleNotes = null
    )
Is this a compiler/IDE bug?
s
You were calling the secondary constructor recursively
k
🤦‍♂️ duh
thanks
s
🙂 We’ve all been there 🙂
k
the imposter syndrome is strong this morning!! lol
276 Views