diff --git a/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjectionResolution.kt b/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjectionResolution.kt index 2814d571e..7737ceecd 100644 --- a/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjectionResolution.kt +++ b/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjectionResolution.kt @@ -152,10 +152,7 @@ private fun InjectablesScope.computeForCandidate( candidate.dependencies.first().type == previousCandidate.dependencies.first().type else previousCandidate.chainFqName == candidate.chainFqName - if (isSameCallable && - previousCandidate.type.coveringSet == candidate.type.coveringSet && - (previousCandidate.type.typeSize < candidate.type.typeSize || - previousCandidate.type == candidate.type)) { + if (isSameCallable && previousCandidate.type == candidate.type) { val result = ResolutionResult.Failure.WithCandidate.DivergentInjectable(candidate) resultsByCandidate[candidate] = result return result @@ -173,10 +170,7 @@ private fun InjectablesScope.resolveCandidates( request: InjectableRequest, candidates: List ): ResolutionResult { - if (candidates.size == 1) { - val candidate = candidates.single() - return resolveCandidate(candidate) - } + if (candidates.size == 1) return resolveCandidate(candidates.single()) val successes = mutableListOf() var failure: ResolutionResult.Failure? = null diff --git a/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjektType.kt b/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjektType.kt index b2a09d76d..93a74f4f5 100644 --- a/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjektType.kt +++ b/compiler/src/main/kotlin/com/ivianuu/injekt/compiler/resolution/InjektType.kt @@ -349,32 +349,6 @@ fun InjektType.render( inner() } -val InjektType.typeSize: Int - get() { - var typeSize = 0 - val seen = mutableSetOf() - fun visit(type: InjektType) { - typeSize++ - if (seen.add(type)) - type.arguments.forEach { visit(it) } - } - visit(this) - return typeSize - } - -val InjektType.coveringSet: Set - get() { - val classifiers = mutableSetOf() - val seen = mutableSetOf() - fun visit(type: InjektType) { - if (!seen.add(type)) return - classifiers += type.classifier - type.arguments.forEach { visit(it) } - } - visit(this) - return classifiers - } - val InjektType.typeDepth: Int get() = (arguments.maxOfOrNull { it.typeDepth } ?: 0) + 1 fun InjektType.isProvideFunctionType(ctx: InjektContext): Boolean = diff --git a/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/DivergenceTest.kt b/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/DivergenceTest.kt deleted file mode 100644 index 50dae1350..000000000 --- a/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/DivergenceTest.kt +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 Manuel Wrage. Use of this source code is governed by the Apache 2.0 license. - */ - -@file:OptIn(ExperimentalCompilerApi::class) - -package com.ivianuu.injekt.integrationtests - -import org.jetbrains.kotlin.compiler.plugin.* -import org.junit.* - -class DivergenceTest { - @Test fun testUnresolvableDivergence() = singleAndMultiCodegen( - """ - interface Base - - interface Wrapper : Base { - val value: T - } - - @Provide fun unwrapped(wrapped: Wrapper): T = wrapped.value - """, - """ - fun invoke() = inject() - """ - ) { - compilationShouldHaveFailed("diverging") - } - - @Test fun testResolvableDivergence() = singleAndMultiCodegen( - """ - interface Base - - interface Wrapper : Base { - val value: T - } - - @Provide fun unwrapped(wrapped: Wrapper): T = wrapped.value - - @Provide fun baseWrapper(): Wrapper> = error("") - """, - """ - fun invoke() = inject() - """ - ) - - @Test fun testCircularDependencyFails() = singleAndMultiCodegen( - """ - @Provide class A(b: B) - @Provide class B(a: A) - """, - """ - fun invoke() = inject() - """ - ) { - compilationShouldHaveFailed("diverging") - } - - @Test fun testLambdaBreaksCircularDependency() = singleAndMultiCodegen( - """ - @Provide class A(b: B) - @Provide class B(a: (B) -> A) { - val a = a(this) - } - """, - """ - fun invoke() = inject() - """ - ) { - invokeSingleFile() - } -} diff --git a/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/ResolutionTest.kt b/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/ResolutionTest.kt index 30f064b4c..e6ee7a203 100644 --- a/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/ResolutionTest.kt +++ b/integration-tests/src/test/kotlin/com/ivianuu/injekt/integrationtests/ResolutionTest.kt @@ -334,4 +334,30 @@ class ResolutionTest { ) { compilationShouldHaveFailed("ambiguous") } + + @Test fun testCircularDependencyFails() = singleAndMultiCodegen( + """ + @Provide class A(b: B) + @Provide class B(a: A) + """, + """ + fun invoke() = inject() + """ + ) { + compilationShouldHaveFailed("diverging") + } + + @Test fun testLambdaBreaksCircularDependency() = singleAndMultiCodegen( + """ + @Provide class A(b: B) + @Provide class B(a: (B) -> A) { + val a = a(this) + } + """, + """ + fun invoke() = inject() + """ + ) { + invokeSingleFile() + } }