[LL API] Check raw expect/actual modifiers in PSI-FIR comparison
There might be both common and JVM artifacts of the same library in dependencies.
This commit is contained in:
+12
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.analysis.low.level.api.fir.api
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.sessions.createEmptySession
|
||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.util.errorWithFirSpecificEntries
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.parentsOfType
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.builder.BodyBuildingMode
|
||||
@@ -24,14 +25,18 @@ import org.jetbrains.kotlin.fir.types.impl.FirImplicitNullableAnyTypeRef
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtConstructor
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtFunction
|
||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasActualModifier
|
||||
import org.jetbrains.kotlin.psi.psiUtil.hasExpectModifier
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
// TODO replace with structural type comparison?
|
||||
object KtDeclarationAndFirDeclarationEqualityChecker {
|
||||
fun representsTheSameDeclaration(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
||||
if (!modifiersMatch(psi, fir)) return false
|
||||
if (!receiverTypeMatch(psi, fir)) return false
|
||||
if (!returnTypesMatch(psi, fir)) return false
|
||||
if (!typeParametersMatch(psi, fir)) return false
|
||||
@@ -39,6 +44,13 @@ object KtDeclarationAndFirDeclarationEqualityChecker {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun modifiersMatch(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
||||
// According to asymmetric logic in 'RawFirBuilder'
|
||||
if (psi.parentsOfType<KtDeclaration>().any { it.hasExpectModifier() } != fir.symbol.rawStatus.isExpect) return false
|
||||
if (psi.hasActualModifier() != fir.symbol.rawStatus.isActual) return false
|
||||
return true
|
||||
}
|
||||
|
||||
private fun receiverTypeMatch(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
||||
if ((fir.receiverParameter != null) != (psi.receiverTypeReference != null)) return false
|
||||
if (fir.receiverParameter != null && !isTheSameTypes(psi.receiverTypeReference!!, fir.receiverParameter!!.typeRef, isVararg = false)) {
|
||||
|
||||
Reference in New Issue
Block a user