Open
Description
Describe the bug
Building a type name for a type whose bound is recursively generic produces a stack overflow.
However, this pattern of use of generics is very common, and used also in the standard library (see example).
To Reproduce
Consider the following main
:
import com.squareup.kotlinpoet.asTypeName
import kotlin.reflect.jvm.kotlinFunction
fun main() {
Class.forName("kotlin.collections.ArraysKt").methods.first {
// Selects fun <T : Comparable<T>> Array<T>.max(): T
it.name == "max" && it.parameters.first().parameterizedType.typeName.contains("Comparable")
}.kotlinFunction?.parameters?.first()?.type
?.asTypeName() // Stack overflow due to the recurring type.
}
Expected behavior
A TypeName
for T : Comparable<T>
is produced.
Additional context
We are writing a code generator that runs through the standard library, and we noticed we cannot use it on comparators.
Activity