ConeTypeContext: handle "recursive type alias" situation

This commit is contained in:
Mikhail Glukhikh
2019-06-24 11:06:04 +03:00
parent 152abbfb4c
commit 1e1f4d4472
@@ -383,9 +383,28 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext {
return types.first() // TODO: proper implementation
}
private fun prepareClassLikeType(
type: ConeClassLikeType,
visited: MutableSet<ConeAbbreviatedType>
): KotlinTypeMarker {
return when (type) {
is ConeAbbreviatedType -> prepareAbbreviatedType(type, visited)
else -> type
}
}
private fun prepareAbbreviatedType(
type: ConeAbbreviatedType,
visited: MutableSet<ConeAbbreviatedType> = mutableSetOf()
): KotlinTypeMarker {
if (type in visited) return ConeClassErrorType("Recursive type alias")
visited += type
return prepareClassLikeType(type.directExpansionType(session) ?: ConeClassErrorType("unresolved"), visited)
}
override fun prepareType(type: KotlinTypeMarker): KotlinTypeMarker {
return when (type) {
is ConeAbbreviatedType -> prepareType(type.directExpansionType(session) ?: ConeClassErrorType("unresolved"))
is ConeAbbreviatedType -> prepareAbbreviatedType(type)
else -> type
}
}