From cff576844e8ff7a824970142b5bc4ad6df17df5e Mon Sep 17 00:00:00 2001 From: Ilya Kirillov Date: Tue, 19 Apr 2022 16:59:05 +0200 Subject: [PATCH] [symbol fir] fix checkIsInheritor in LC ^KT-51240 fixed --- .../symbol/classes/firLightClassUtils.kt | 31 +++++-------------- 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/firLightClassUtils.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/firLightClassUtils.kt index 769ca4f02a6..e4fb7886e45 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/firLightClassUtils.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/classes/firLightClassUtils.kt @@ -436,38 +436,21 @@ internal fun KtSymbolWithMembers.createInnerClasses( } internal fun KtClassOrObject.checkIsInheritor(superClassOrigin: KtClassOrObject, checkDeep: Boolean): Boolean { - val subClassOrigin = this - - fun KtAnalysisSession.check(): Boolean { - val subClassSymbol = subClassOrigin.getClassOrObjectSymbol() + return analyseForLightClasses(this) { + if (!superClassOrigin.canBeAnalysed()) { + return false + } + val subClassSymbol = this@checkIsInheritor.getClassOrObjectSymbol() val superClassSymbol = superClassOrigin.getClassOrObjectSymbol() - if (subClassSymbol == superClassSymbol) return false + if (subClassSymbol == superClassSymbol) return@analyseForLightClasses false - return if (checkDeep) { + if (checkDeep) { subClassSymbol.isSubClassOf(superClassSymbol) } else { 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