Skip to content

Commit

Permalink
,,,
Browse files Browse the repository at this point in the history
  • Loading branch information
IVIanuu committed Feb 25, 2024
1 parent 6fcd936 commit 5d63136
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -173,10 +170,7 @@ private fun InjectablesScope.resolveCandidates(
request: InjectableRequest,
candidates: List<Injectable>
): ResolutionResult {
if (candidates.size == 1) {
val candidate = candidates.single()
return resolveCandidate(candidate)
}
if (candidates.size == 1) return resolveCandidate(candidates.single())

val successes = mutableListOf<ResolutionResult.Success>()
var failure: ResolutionResult.Failure? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,32 +349,6 @@ fun InjektType.render(
inner()
}

val InjektType.typeSize: Int
get() {
var typeSize = 0
val seen = mutableSetOf<InjektType>()
fun visit(type: InjektType) {
typeSize++
if (seen.add(type))
type.arguments.forEach { visit(it) }
}
visit(this)
return typeSize
}

val InjektType.coveringSet: Set<InjektClassifier>
get() {
val classifiers = mutableSetOf<InjektClassifier>()
val seen = mutableSetOf<InjektType>()
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 =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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<A>()
"""
) {
compilationShouldHaveFailed("diverging")
}

@Test fun testLambdaBreaksCircularDependency() = singleAndMultiCodegen(
"""
@Provide class A(b: B)
@Provide class B(a: (B) -> A) {
val a = a(this)
}
""",
"""
fun invoke() = inject<B>()
"""
) {
invokeSingleFile()
}
}

0 comments on commit 5d63136

Please sign in to comment.