Skip to content

Commit dcd3e56

Browse files
Fix @single(createdAtStart=true) silently dropped on definition functions
@module(createdAtStart) and @singleton classes were fixed in RC3.13, but buildFunctionDefinitionCall — the path for @Single/@singleton definition FUNCTIONS inside a @module — never propagated the per-definition createdAtStart flag. The generated buildSingle(...) fell back to the Kotlin default-arg trampoline (false), so eager init was silently lost (koin#2425/#2415). Propagate createdAtStart to buildSingle for SINGLE function definitions, mirroring the class- and top-level-function builders. Adds box regression test single_fun_created_at_start with a NON-eager @module (so the module-level flag can't mask the per-definition one): asserts the eager fun is constructed at createEagerInstances() and the lazy fun is not. Behaviorally proven (pre-fix: eagerCtor=0 / fails; post-fix: passes). Full box suite green. Fixes #2425, #2415
1 parent 238743a commit dcd3e56

5 files changed

Lines changed: 467 additions & 0 deletions

File tree

koin-compiler-plugin/src/org/koin/compiler/plugin/ir/DefinitionCallBuilder.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ class DefinitionCallBuilder(
211211
targetFunction, returnTypeClass, moduleClass, builder, parentFunction, getterFunction
212212
)
213213
putRegularArgument(2, definitionLambda)
214+
215+
// Add createdAtStart parameter if applicable (only for SINGLE).
216+
// Without this, `@Single(createdAtStart = true) fun ...` inside a @Module
217+
// silently falls back to the buildSingle default (false) — koin#2425.
218+
if (definition.createdAtStart && definition.definitionType == DefinitionType.SINGLE) {
219+
val createdAtStartIndex = koinFunction.regularParameters.indexOfFirst {
220+
it.name.asString() == "createdAtStart"
221+
}
222+
if (createdAtStartIndex >= 0) {
223+
putRegularArgument(createdAtStartIndex, builder.irTrue())
224+
}
225+
}
214226
}
215227

216228
return if (definition.bindings.isNotEmpty()) {

koin-compiler-plugin/test-gen/org/jetbrains/kotlin/compiler/plugin/template/runners/JvmBoxTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public void testModule_created_at_start() {
4242
runTest("koin-compiler-plugin/testData/box/annotations/module_created_at_start.kt");
4343
}
4444

45+
@Test
46+
@TestMetadata("single_fun_created_at_start.kt")
47+
public void testSingle_fun_created_at_start() {
48+
runTest("koin-compiler-plugin/testData/box/annotations/single_fun_created_at_start.kt");
49+
}
50+
4551
@Test
4652
@TestMetadata("singleton_class.kt")
4753
public void testSingleton_class() {

0 commit comments

Comments
 (0)