Repository navigation
fix: no false KOIN-D002 on a Koin built elsewhere (#58), no false KOIN-D006 on activityViewModel (#121) - #136
Merged
Conversation
A `get<T>()` was judged against whatever koinApplication/startKoin the compilation declared, even on a Koin built elsewhere: a shared test fixture's instance, a parameter, a stored property. That gave false KOIN-D002, mostly in test source sets (#58). Every call site is still judged exactly as before, except: - Koin.get/inject/Scope.get on a Koin that is provably foreign: a function parameter, a lateinit var, a property with a custom getter or by lazy, or a non-Koin function's result (an overridden getKoin(), a fixture's koin). Seen through val, casts and !!; a plain val is followed to its initializer, so `val appKoin = startKoin { }.koin` stays judged. - global resolvers (KoinComponent, Compose, Android, Ktor), when every entry point is a plain koinApplication { } (a test fixture or a preview). Such a call site that would have been KOIN-D002 is neither an error nor a hint; one KOIN-W009 per compilation counts them. An unrecognised shape keeps the old behavior: at worst an old false D002, never a lost error. Behavior change: `fun f(koin: Koin) = koin.get<X>()` in an app module, with X defined nowhere, now gives KOIN-W009 instead of KOIN-D002. Known limit: a judged call site is still checked against every graph of the compilation, merged (documented). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ty's instance (#121) activityViewModel / getActivityViewModel / koinActivityViewModel return the ViewModel the activity created with its own parametersOf, so a missing parametersOf there is not an error: - a call site in the same compilation creates that ViewModel with parametersOf → nothing reported; - none does → new KOIN-W010 warning. The creator is often in another Gradle module (activity in :app, fragment in :feature), so this can't be D006; if nothing creates it first, this call creates it without parameters and fails at runtime. KOIN-D005 (wrong parametersOf) and the missing-type check are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 2, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two false errors that push people to turn
compileSafetyoff, mostly in test source sets.#58 —
koin.get<T>()on a Koin built elsewhereA call site was judged against whatever
koinApplication { }/startKoin { }the compilation declared, even when itsKoincame from somewhere else: a shared test fixture, a function parameter, a stored property. One spec building a small isolated graph was enough to make every other spec'sfixture.koin.get<T>()a falseKOIN-D002.Every call site is still judged exactly as before, except:
Koin: a function parameter, alateinit var, a property with a custom getter orby lazy, or the result of a non-Koin function (a fixture'skoin, an overriddengetKoin()). Seen throughval, casts and!!; a plainvalis followed to its initializer, soval appKoin = startKoin { }.koinstays judged.KoinComponent,koinInject,koinViewModel, Android, Ktor) when every entry point is a plainkoinApplication { }(a test fixture or a preview).koinConfiguration { }still counts as an app root (compileSafety: Checks are bypassed when using KoinApplication Composable in Compose Multiplatform project #38).A skipped call site that would have been
KOIN-D002is neither an error nor a hint: one newKOIN-W009per compilation counts them. Any shape not recognised keeps the old behavior, so the worst case is an old falseD002, never a lost error.#121 —
activityViewModel()andparametersOfactivityViewModel<T>()reuses the instance the activity created with its ownparametersOf. It no longer getsKOIN-D006:TwithparametersOf→ nothing reported;KOIN-W010warning. The creator is often in another Gradle module (activity in:app, fragment in:feature), so this can't be an error.KOIN-D005(wrongparametersOf) and the missing-type check are unchanged.fun f(koin: Koin) = koin.get<X>()in an app module, withXdefined nowhere, now givesKOIN-W009instead ofKOIN-D002.KOIN-W009andKOIN-W010; like the otherKOIN-Wcodes they fail builds usingallWarningsAsErrors.Known limit (documented)
A judged call site is still checked against every graph of the compilation, merged: with two
koinApplication { }blocks,a.koin.get<T>()passes when only the other one providesT. Unchanged from before.Tests
D002(getKoin()in aKoinComponentor a definition lambda,koinApplication { }.koin,val x = startKoin { }.koin,koinConfiguration, AndroidgetKoin(),activityViewModelof an undefined type).test-apps:compileKotlinIosArm64,compileKotlinWasmJs,compileKotlinJs,jvmTestgreen.:appmain, unit-test and androidTest compiles green; removing a definition still fails withKOIN-D002at itsby inject()call site.Docs:
docs/COMPILE_TIME_SAFETY.mdgains "Which call sites are judged" and theactivityViewModel()rule. Release notes:RELEASE_NOTES_1.2.2.md.