Anmol Verma
04/01/2023, 4:01 PM1.8.10
and my kmp library starts complaining for
Expected class XXX does not have default constructor
this happens, when I have created a DSL in the commonMain like
public inline fun buildXXX(builderDsl: XXX.() -> Unit):
XXX = XXX().apply(builderDsl).build()
anyone faced something like this before ? 🤔Chris Lee
04/01/2023, 4:18 PMXXX
look like? That code is specifically invoking it’s default constructor via XXX()
Anmol Verma
04/01/2023, 4:25 PMpublic expect class XXXDSL {
public var byte: Int?
public fun build(): XXX
}
public expect inline fun kmXXX(builderDsl: XXXDSL.() -> Unit):
XXX
Anmol Verma
04/01/2023, 4:26 PMrusshwolf
04/01/2023, 4:28 PMXXX()
from common, you need to do expect class XXX()
rather than expect class XXX
russhwolf
04/01/2023, 4:29 PMactual class XXX actual constructor()
etc etc)Anmol Verma
04/01/2023, 4:33 PMexpect class XXX()
it just generates expect class XXX {}
russhwolf
04/01/2023, 4:34 PMXXX()
if that's validAnmol Verma
04/01/2023, 4:36 PMFunSpec.constructorBuilder()
.build()
but somehow it doesn't add the ()
to the class name sad panda
TypeSpec
.classBuilder(dslBuilderClassName)
.addModifiers(modifier)
.primaryConstructor(
///// here FunSpec.constructorBuilder()
.build()
)
russhwolf
04/01/2023, 4:49 PMAnmol Verma
04/01/2023, 4:52 PMpublic 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 🙏russhwolf
04/01/2023, 4:54 PMactual
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.