You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c4e54be
Browse filesBrowse the repository at this point in the historyBrowse files
fix: no false KOIN-D002 on a Koin built elsewhere (#58), no false KOIN-D006 on activityViewModel (#121) (#136)
* fix: judge a call site only when its Koin isn't provably foreign (#58)
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>
* fix: no false KOIN-D006 on activityViewModel, which reuses the activity'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>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: RELEASE_NOTES_1.2.2.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,15 @@ Compile safety on Kotlin/Native and wasm/JS now sees your whole graph.
3
3
## 🐛 Fixed
4
4
5
5
- On Kotlin/Native, wasm and JS, definitions from another Gradle module were invisible to compile safety: `@ComponentScan` classes, DSL definitions, `@InjectedParam` shapes and deferred call sites. You got a false `KOIN-D002` on valid code, or a real missing dependency passed the build. Always the case on Kotlin 2.4.20, and on earlier versions for modules without `@Configuration` (#105, #106, #113). If you turned `compileSafety` off for your Native or wasm targets, turn it back on. JVM and Android were not affected.
6
+
- False `KOIN-D002` on `koin.get<T>()` when that `Koin` was built elsewhere: by a test helper, received as a parameter, or held in a property. It was checked against the graph of an unrelated `koinApplication { }` in the same compilation, which mostly hit test source sets (#58).
7
+
- False `KOIN-D006` on `activityViewModel<T>()` for a ViewModel with `@InjectedParam`: it reuses the instance the activity created with `parametersOf()` (#121). When nothing in the module creates it that way, you get the new `KOIN-W010` warning instead.
6
8
7
9
## 🔧 Changed
8
10
9
11
-**Real errors now reported on Native and wasm/JS.** Missing dependencies, missing `parametersOf()` and deferred call sites are now checked the same way as on JVM. A build that was green on these targets can now fail on a real problem.
10
12
-**New `KOIN-W008` warning.** When the plugin can't see a module's definitions, it now says so and names the module instead of skipping the check silently. Typical causes: the module was built with an older plugin version, its `@ComponentScan` matches nothing, or it is not a direct dependency. This applies to every target, JVM included, and fails builds that use `allWarningsAsErrors`.
13
+
-**New `KOIN-W009` warning, and one fewer error.** A call on a `Koin` that comes from your own code (a function parameter, a property of your class, a helper's instance) is no longer checked against this compilation's graph. When its type is defined nowhere in the compilation, one warning per compilation counts these calls instead of failing the build. So `fun f(koin: Koin) = koin.get<X>()` in your app module, with `X` undefined, now gives `KOIN-W009` instead of `KOIN-D002`. Calls through `KoinComponent`, `getKoin()`, `koinInject` or `by inject()` are still checked where `startKoin` is called.
14
+
-**New `KOIN-W010` warning** on `activityViewModel<T>()` without `parametersOf()` when nothing in the module creates `T` with `parametersOf()` (see Fixed). Both new warnings fail builds that use `allWarningsAsErrors`.
11
15
-**KMP libraries checking their KLIB ABI** (`apiCheck`) will see new `org.koin.plugin.hints` entries once. Run `apiDump`. These hints were always meant to be published; on JVM they already were.
Copy file name to clipboardExpand all lines: docs/COMPILE_TIME_SAFETY.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,6 +133,34 @@ or a module class off the classpath). Compile-time dependency checks are skipped
133
133
134
134
Usual causes: the dependency was built by an older plugin version, its `@ComponentScan` matches nothing, or the module sits more than one `implementation` hop away. Rebuild it with the same plugin version, or add it as a direct dependency.
135
135
136
+
### Which call sites are judged
137
+
138
+
Every call site is judged against this compilation's graph, except two cases:
139
+
140
+
| Call site | Judged here when |
141
+
|---|---|
142
+
|`koin.get()` / `koin.getScope(..).get()` on a `Koin` that comes from outside Koin's API: a function parameter, a `lateinit var`, a property with a custom getter or `by lazy`, a function of your own (`TestFixture().koin`, an overridden `getKoin()`) | never — the same shape holds your app's Koin or a test helper's, so its graph is unknown here |
143
+
|`KoinComponent.get()` / `by inject()`, `koinInject()`, `koinViewModel()`, Android `viewModel()`, Ktor | unless every entry point here is a plain `koinApplication { }` (a test fixture, a preview) |
144
+
145
+
Everything else is judged as before, including `get()` in a definition lambda, `koinApplication { }.koin`, a `val` initialized with `startKoin { }.koin`, `getKoin()` and `with(koin) { }`.
146
+
147
+
A call site that isn't judged here and whose type nothing in this compilation defines is not an error. It is never dropped silently: one `KOIN-W009` per compilation counts them.
148
+
149
+
```
150
+
[Koin][KOIN-W009] 3 call site(s) not validated at compile time (first: get<Clock>()): their type is
151
+
not defined in this compilation, and they resolve on a Koin instance whose modules it can't see.
152
+
They are only checked at runtime.
153
+
```
154
+
155
+
Known limit: a judged call site is checked against every graph the compilation builds, merged. With two `koinApplication { }` blocks in one compilation, `a.koin.get<T>()` passes when only the other one provides `T`.
156
+
157
+
### `activityViewModel()` and `parametersOf`
158
+
159
+
`activityViewModel<T>()` returns the instance the activity created. When `T` has `@InjectedParam` and the call passes no `parametersOf(...)`:
160
+
161
+
- a call site in the same module creates `T` with `parametersOf(...)` → nothing reported;
162
+
- none does → `KOIN-W010`. The creator may be in another module; if nothing creates `T` first, this call creates it without parameters and fails at runtime.
163
+
136
164
## External Types: `@Provided` and Whitelist
137
165
138
166
Some types are provided by the platform or framework at runtime (e.g., Android's `Context`, `SavedStateHandle`) and are never declared as Koin definitions. Without special handling, these would trigger false "missing dependency" errors.
0 commit comments