Skip to content

Commit

Permalink
Fix jdeps collectTypeArguments stackoverflow error
Browse files Browse the repository at this point in the history
Fixes #485
  • Loading branch information
Bencodes authored Feb 18, 2021
1 parent 912e294 commit 51fe508
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.extensions.StorageComponentContainerContributor
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
import org.jetbrains.kotlin.load.java.descriptors.JavaPropertyDescriptor
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
Expand Down Expand Up @@ -230,11 +229,14 @@ class JdepsGenExtension(
collectTypeArguments(kotlinType)
}

fun collectTypeArguments(kotlinType: KotlinType) {
fun collectTypeArguments(kotlinType: KotlinType, visitedKotlinTypes: MutableSet<KotlinType> = mutableSetOf()) {
visitedKotlinTypes.add(kotlinType)
kotlinType.arguments.map { it.type }.forEach { typeArgument ->
addExplicitDep(typeArgument)
typeArgument.supertypes().forEach { addImplicitDep(it) }
collectTypeArguments(typeArgument)
if (!visitedKotlinTypes.contains(typeArgument)) {
collectTypeArguments(typeArgument, visitedKotlinTypes)
}
}
}
}
Expand Down

0 comments on commit 51fe508

Please sign in to comment.