Skip to content

Commit

Permalink
Fix StackOverflowError on types with self-references
Browse files Browse the repository at this point in the history
  • Loading branch information
psteiger committed Feb 14, 2024
1 parent dfb9036 commit 13ad53a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/ast/src/main/kotlin/com/uber/xprocessing/ext/XType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,16 @@ fun XType.isPrimitive(): Boolean {
}

private fun XType.hasCollectionType(): Boolean {
return this.typeElement?.name.orEmpty() in collectionTypes ||
typeArguments.any { it.hasCollectionType() }
val visited = mutableSetOf<XType>()
val queue = mutableListOf(this@hasCollectionType)
while (queue.isNotEmpty()) {
val type = queue.removeFirst()
if (type in visited) continue
if (type.typeElement?.name in collectionTypes) return true
visited.add(type)
queue.addAll(type.typeArguments)
}
return false
}

private val collectionTypes =
Expand Down

0 comments on commit 13ad53a

Please sign in to comment.