FIR: Simplify supertypes scopes computation
This commit is contained in:
@@ -42,6 +42,39 @@ fun lookupSuperTypes(
|
||||
}
|
||||
}
|
||||
|
||||
fun FirClass<*>.isThereLoopInSupertypes(session: FirSession): Boolean {
|
||||
val visitedSymbols: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
|
||||
val inProcess: MutableSet<FirClassifierSymbol<*>> = mutableSetOf()
|
||||
|
||||
var isThereLoop = false
|
||||
|
||||
fun dfs(current: FirClassifierSymbol<*>) {
|
||||
if (current in visitedSymbols) return
|
||||
if (!inProcess.add(current)) {
|
||||
isThereLoop = true
|
||||
return
|
||||
}
|
||||
|
||||
when (val fir = current.fir) {
|
||||
is FirClass<*> -> {
|
||||
fir.superConeTypes.forEach {
|
||||
it.lookupTag.toSymbol(session)?.let(::dfs)
|
||||
}
|
||||
}
|
||||
is FirTypeAlias -> {
|
||||
fir.expandedConeType?.lookupTag?.toSymbol(session)?.let(::dfs)
|
||||
}
|
||||
}
|
||||
|
||||
visitedSymbols.add(current)
|
||||
inProcess.remove(current)
|
||||
}
|
||||
|
||||
dfs(symbol)
|
||||
|
||||
return isThereLoop
|
||||
}
|
||||
|
||||
fun lookupSuperTypes(
|
||||
symbol: FirClassifierSymbol<*>,
|
||||
lookupInterfaces: Boolean,
|
||||
|
||||
Reference in New Issue
Block a user