File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed
projects/core/koin-core/src
commonMain/kotlin/org/koin/core/resolution
commonTest/kotlin/org/koin/core Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -128,7 +128,7 @@ class CoreResolver(
128128 scope : Scope ,
129129 ctx : ResolutionContext ,
130130 ): T ? {
131- val parentScope = if (scope.linkedScopes.size > 1 ) flatten(scope.linkedScopes) else scope.linkedScopes
131+ val parentScope = flatten(scope.linkedScopes)
132132 return parentScope.firstNotNullOfOrNull {
133133 ctx.logger.debug(" |- ? ${ctx.debugTag} look in scope '${it.id} '" )
134134 val instanceContext = if (! it.isRoot) ctx.newContextForScope(it) else ctx
@@ -164,9 +164,9 @@ fun flatten(scopes: List<Scope>): Set<Scope> {
164164 if (! flatten.add(current)) {
165165 continue
166166 }
167- for (module in current.linkedScopes) {
168- if (module !in flatten) {
169- stack + = module
167+ for (scope in current.linkedScopes) {
168+ if (scope !in flatten) {
169+ stack + = scope
170170 }
171171 }
172172 }
Original file line number Diff line number Diff line change @@ -199,4 +199,30 @@ class ScopeTest {
199199 assertEquals(id, single.id)
200200 scope.close()
201201 }
202+
203+ @Test
204+ fun scope_regression_test (){
205+ startKoin {
206+ modules(
207+ module {
208+ single<Unit > {}
209+ scope(named(" one" )) {}
210+ scope(named(" two" )) {
211+ scoped<String > {
212+ get<Unit >().toString() // gets Unit from the root scope
213+ }
214+ }
215+ },
216+ )
217+ }.run {
218+ val one = koin.createScope(" one" , named(" one" ))
219+ val two = koin.createScope(" two" , named(" two" )).apply {
220+ unlink(getScope(" _root_" ))
221+ linkTo(one)
222+ }
223+ // in 4.1.0-Beta11 -> prints "kotlin.Unit"
224+ // in 4.1.0-RC1 -> throws NoDefinitionFoundException
225+ assertEquals(Unit .toString(),two.get<String >())
226+ }
227+ }
202228}
You can’t perform that action at this time.
0 commit comments