min
08/28/2026, 11:02 AM.createMemberFunction(
owner = nestedItem,
name = COMPANION_METHOD_TO_GENERATE,
returnType = outerClass.constructType(),
key = KEY,
) {
val functionBuilder = this
functionBuilder.status {
val statusBuilder = this
statusBuilder.isOperator = true
}
ctor.valueParameters.forEach { parameter ->
functionBuilder.valueParameter(
name = parameter.name,
type = parameter.returnTypeRef.coneType,
)
}
}
How do I also copy over all existing default values of constructor parameters?min
08/28/2026, 11:04 AMthis: FirDeclarationGenerationExtension and ctor is
outerClass.fir
.declarations
.filterIsInstance<FirConstructor>()
.firstOrNull(FirConstructor::isPrimary)
.let { nullable -> nullable ?: break }Youssef Shoaib [MOD]
08/28/2026, 11:18 AMIf you set [hasDefaultValue] to true then you need to generate actual default value in [IrGenerationExtension]
In general, it's not recommended to generate bodies in FIR, and instead you're supposed to do it in IR (where it's easier anyway). So simply set
hasDefaultValue = true, then copy it in IR.
If you really really want, I think you can .createMemberFunction(...).apply { } and edit the value parameters insidePavel Kunyavskiy [JB]
08/28/2026, 11:20 AMmin
08/29/2026, 9:50 AMmin
08/29/2026, 9:51 AMPavel Kunyavskiy [JB]
08/29/2026, 9:58 AMprivate fun toY(x: T): T
fun <T> foo(x: T, y: T = toY(x))
You need to make sure, that
• toY is accessible from generated function
• x in default value references x from new function, not from old one
• type of this expression references T from new function not from old one.
The first case is about something like
//Other module
interface I {
fun foo(x: Int = 10)
}
// Your module
claas C : I {
fun foo(x: Int)
}
In that case C.foo is callable with default, but compiler doesn't know the value of default at all.Pavel Kunyavskiy [JB]
08/29/2026, 10:00 AMYoussef Shoaib [MOD]
08/29/2026, 10:01 AMclass Foo(val x: Int, val y: Int = x)
you'll need to map the default value so any references to other parameters refer to the new declaration you're makingPavel Kunyavskiy [JB]
08/29/2026, 10:04 AM