Hi Folks, I just updated to `1.8.10` and my kmp library starts complaining for ```Expected class XXX...
a
Hi Folks, I just updated to
1.8.10
and my kmp library starts complaining for
Copy code
Expected class XXX does not have default constructor
this happens, when I have created a DSL in the commonMain like
Copy code
public inline fun buildXXX(builderDsl: XXX.() -> Unit):
    XXX = XXX().apply(builderDsl).build()
anyone faced something like this before ? 🤔
c
What does
XXX
look like? That code is specifically invoking it’s default constructor via
XXX()
a
Copy code
public expect class XXXDSL {
    public var byte: Int?

    public fun build(): XXX
}

public expect inline fun kmXXX(builderDsl: XXXDSL.() -> Unit):
    XXX
I actually modified it to something like this now, and it works 🤷
r
If you want to call
XXX()
from common, you need to do
expect class XXX()
rather than
expect class XXX
(and then
actual class XXX actual constructor()
etc etc)
a
I was using kotlin poet and somehow it doesn’t generate
expect class XXX()
it just generates
expect class XXX {}
r
I think you need to add the constructor explicitly in Kotlinpoet. It'll shorten it to
XXX()
if that's valid
a
Yes i am adding it using
Copy code
FunSpec.constructorBuilder()
                        .build()
but somehow it doesn't add the
()
to the class name sad panda
Copy code
TypeSpec
                .classBuilder(dslBuilderClassName)
                .addModifiers(modifier)
                .primaryConstructor(
                 ///// here FunSpec.constructorBuilder()
                        .build()
                )
r
In that case, I'm not sure what's going wrong. Maybe try asking in #squarelibraries
a
I mean for now, If i make the dsl builder fun to expect
Copy code
public expect inline fun kmXXX(builderDsl: XXXDSL.() -> Unit):
    XXX
and generate an actual func for it with the impl code it works, so maybe it's a KMP thing 🤷‍♂️ not sure though 😑 , will post once i see this as a blocker. but really thanks for helping with your insights 🙏
r
I'm guessing that works because the
actual
declarations for the builder fun can find the
actual
declarations for the constructor, since it's all in platform code at that point. But it shouldn't be necessary.