[symbol fir] fix checkIsInheritor in LC

^KT-51240 fixed
This commit is contained in:
Ilya Kirillov
2022-04-19 16:59:05 +02:00
parent 2e515f3945
commit cff576844e
@@ -436,38 +436,21 @@ internal fun KtSymbolWithMembers.createInnerClasses(
} }
internal fun KtClassOrObject.checkIsInheritor(superClassOrigin: KtClassOrObject, checkDeep: Boolean): Boolean { internal fun KtClassOrObject.checkIsInheritor(superClassOrigin: KtClassOrObject, checkDeep: Boolean): Boolean {
val subClassOrigin = this return analyseForLightClasses(this) {
if (!superClassOrigin.canBeAnalysed()) {
fun KtAnalysisSession.check(): Boolean { return false
val subClassSymbol = subClassOrigin.getClassOrObjectSymbol() }
val subClassSymbol = this@checkIsInheritor.getClassOrObjectSymbol()
val superClassSymbol = superClassOrigin.getClassOrObjectSymbol() val superClassSymbol = superClassOrigin.getClassOrObjectSymbol()
if (subClassSymbol == superClassSymbol) return false if (subClassSymbol == superClassSymbol) return@analyseForLightClasses false
return if (checkDeep) { if (checkDeep) {
subClassSymbol.isSubClassOf(superClassSymbol) subClassSymbol.isSubClassOf(superClassSymbol)
} else { } else {
subClassSymbol.isDirectSubClassOf(superClassSymbol) subClassSymbol.isDirectSubClassOf(superClassSymbol)
} }
} }
// Due to the KT-51240 we cannot be sure which PSI element is better to analyse, so we try both.
//
// We specifically catch NoCacheForModuleException as a sign that LLFirSessionProvider.getModuleCache could not
// find a cache for the passed module. This means that `module(subClassOrigin)` does not have `module(superClassOrigin)` as
// its dependency, and we should try the other way around.
//
// Note, however, that the second call might also fail, since the modules can be completely independent.
// We can only hope that, since this code is invoked from the light classes, the passed PSI classes are
// relatively close to each other syntactically, meaning that there is some dependency between the modules
// they reside in.
//
// TODO: Avoid this hack when KT-51240 is fixed
return try {
analyseForLightClasses(subClassOrigin) { check() }
} catch (e: NoCacheForModuleException) {
analyseForLightClasses(superClassOrigin) { check() }
}
} }
private val KtSymbolWithTypeParameters.hasReifiedParameters: Boolean private val KtSymbolWithTypeParameters.hasReifiedParameters: Boolean