Skip to content

Fix @Single(createdAtStart=true) silently dropped on definition functions#57

Merged
arnaudgiuliani merged 1 commit into
1.0.1from
arnaud/ktz-4152-createdatstart
Jun 11, 2026
Merged

Fix @Single(createdAtStart=true) silently dropped on definition functions#57
arnaudgiuliani merged 1 commit into
1.0.1from
arnaud/ktz-4152-createdatstart

Conversation

@arnaudgiuliani

Copy link
Copy Markdown
Member

Problem

koin-compiler-plugin silently ignored createdAtStart = true on @Single / @Singleton definition functions inside a @Module. The generated buildSingle(...) fell back to Kotlin's default-arg trampoline (false), so eager singletons were never created at startKoin — no compile error, no warning (koin#2425, koin#2415).

Root cause

createdAtStart propagation existed in buildClassDefinitionCall and buildTopLevelFunctionDefinitionCall, but buildFunctionDefinitionCall (the @Single/@Singleton function inside a @module path) never set it. The module-level fix (RC3.13, @Module(createdAtStart)) masked this in the existing test.

Fix

Propagate createdAtStart to buildSingle(...) for SINGLE function definitions, mirroring the other two builders.

Tests & samples

  • Box test single_fun_created_at_start in a deliberately non-eager @ComponentScan module (so the module-level flag can't mask it), exercising both per-definition shapes: @Singleton(createdAtStart=true) class and @Single(createdAtStart=true) fun, each with a lazy counterpart. Verified pre-fix FAIL / post-fix PASS.
  • Sample apps: app-annotations DatabaseModule (eager Room DB open) and app-kmp-klib (@Single(createdAtStart=true) exercised on iosArm64).

Full box suite green.

Fixes InsertKoinIO/koin#2425, InsertKoinIO/koin#2415

Stacked on the merged compat/dedup/wasmJs fixes already in 1.0.1.

🤖 Generated with Claude Code

- single_fun_created_at_start now exercises BOTH per-definition shapes in one
  non-eager @componentscan module: @singleton(createdAtStart=true) class
  (buildClassDefinitionCall) and @single(createdAtStart=true) fun
  (buildFunctionDefinitionCall), each with a lazy counterpart. Verified pre-fix
  FAIL / post-fix PASS.
- app-annotations DatabaseModule: @singleton(createdAtStart=true) on providesDatabase
  (eager Room DB open at startKoin) — the fixed @Module-function path in a real app.
- app-kmp-klib: @single(createdAtStart=true) fun, exercising the fix on KLIB targets
  (iosArm64 verified).
@arnaudgiuliani arnaudgiuliani merged commit 5a3910d into 1.0.1 Jun 11, 2026
2 checks passed
@arnaudgiuliani arnaudgiuliani deleted the arnaud/ktz-4152-createdatstart branch July 10, 2026 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant