[low level api] consider return type when matching FIR and PSI declarations
This commit is contained in:
+17
-10
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.types.*
|
|||||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitNullableAnyTypeRef
|
import org.jetbrains.kotlin.fir.types.impl.FirImplicitNullableAnyTypeRef
|
||||||
import org.jetbrains.kotlin.name.StandardClassIds
|
import org.jetbrains.kotlin.name.StandardClassIds
|
||||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.KtConstructor
|
||||||
import org.jetbrains.kotlin.psi.KtFunction
|
import org.jetbrains.kotlin.psi.KtFunction
|
||||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
@@ -31,22 +32,28 @@ import org.jetbrains.kotlin.utils.addIfNotNull
|
|||||||
// TODO replace with structural type comparison?
|
// TODO replace with structural type comparison?
|
||||||
object KtDeclarationAndFirDeclarationEqualityChecker {
|
object KtDeclarationAndFirDeclarationEqualityChecker {
|
||||||
fun representsTheSameDeclaration(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
fun representsTheSameDeclaration(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
||||||
if ((fir.receiverTypeRef != null) != (psi.receiverTypeReference != null)) return false
|
if (!receiverTypeMatch(psi, fir)) return false
|
||||||
if (fir.receiverTypeRef != null
|
if (!returnTypesMatch(psi, fir)) return false
|
||||||
&& !isTheSameTypes(
|
|
||||||
psi.receiverTypeReference!!,
|
|
||||||
fir.receiverTypeRef!!,
|
|
||||||
isVararg = false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if (fir is FirFunction) {
|
if (fir is FirFunction) {
|
||||||
if (!typeParametersMatch(fir, psi) || !valueParametersMatch(fir, psi)) return false
|
if (!typeParametersMatch(fir, psi) || !valueParametersMatch(fir, psi)) return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun receiverTypeMatch(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
||||||
|
if ((fir.receiverTypeRef != null) != (psi.receiverTypeReference != null)) return false
|
||||||
|
if (fir.receiverTypeRef != null && !isTheSameTypes(psi.receiverTypeReference!!, fir.receiverTypeRef!!, isVararg = false)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun returnTypesMatch(psi: KtCallableDeclaration, fir: FirCallableDeclaration): Boolean {
|
||||||
|
if (psi is KtConstructor<*>) return true
|
||||||
|
return isTheSameTypes(psi.typeReference!!, fir.returnTypeRef, isVararg = false)
|
||||||
|
}
|
||||||
|
|
||||||
private fun typeParametersMatch(firFunction: FirCallableDeclaration, psiFunction: KtCallableDeclaration): Boolean {
|
private fun typeParametersMatch(firFunction: FirCallableDeclaration, psiFunction: KtCallableDeclaration): Boolean {
|
||||||
if (firFunction.typeParameters.size != psiFunction.typeParameters.size) return false
|
if (firFunction.typeParameters.size != psiFunction.typeParameters.size) return false
|
||||||
val boundsByName = psiFunction.typeConstraints.groupBy { it.subjectTypeParameterName?.getReferencedName() }
|
val boundsByName = psiFunction.typeConstraints.groupBy { it.subjectTypeParameterName?.getReferencedName() }
|
||||||
|
|||||||
Reference in New Issue
Block a user