You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
DanySK
changed the title
Stack overflow when a curiously recurring template pattern (recursively generic type) is used
Stack overflow when a curiously recurring template pattern (recursively bound generic type) is used
May 22, 2024
DanySK
changed the title
Stack overflow when a curiously recurring template pattern (recursively bound generic type) is used
Stack overflow when generating names if types are "curiously recurring" (recursively bound generics)
May 22, 2024
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
:Expected behavior
A
TypeName
forT : 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.
The text was updated successfully, but these errors were encountered: