[FIR, IR] 1/2 Align FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes with ExpectActualUtilsKt.areCompatibleExpectActualTypes

Those two functions are copy-paste of each other. They diverged since
the time they were copy-pasted. This commit makes
FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes
up-to-date.

I didn't update ExpectActualUtilsKt.areCompatibleExpectActualTypes
because I will drop it in the next commit.

Change in `dynamicTypesEqualToAnything` doesn't change any logic (yet.
This change in logic will take effect in the next commit), because:
1. `dynamicTypesEqualToAnything` is only changed in
AbstractExpectActualChecker.getCallablesCheckingIncompatibility. But
AbstractExpectActualChecker.getCallablesCheckingIncompatibility doesn't
check return types on frontend (it only check return types on backend).
2. `dynamicTypesEqualToAnything` is ignored on IR backend

I have no idea what is the difference between `createTypeCheckerState()`
and `actualSession.typeContext`, but it aligns these copy-pasted
versions and makes the tests behave like in K1 (at least
'typeUsageWithUnresolvedReference' and 'kt57320' are affected)

This commit is mainly a preparation for the next commit.

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
This commit is contained in:
Nikita Bobko
2023-10-25 20:43:23 +02:00
committed by teamcity
parent ddc1ae9ac6
commit a9583e4f9a
6 changed files with 17 additions and 4 deletions
@@ -30,6 +30,7 @@ fun createExpectActualTypeParameterSubstitutor(
return substitutor.chain(parentSubstitutor)
}
// Copy-pasted to org.jetbrains.kotlin.fir.resolve.transformers.mpp.FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes
fun areCompatibleExpectActualTypes(
expectedType: ConeKotlinType?,
actualType: ConeKotlinType?,
@@ -28,7 +28,6 @@ import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualCollectionArgumentsCom
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext.AnnotationCallInfo
import org.jetbrains.kotlin.resolve.checkers.OptInNames
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCompatibility
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualMatchingCompatibility
import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.TypeCheckerState
@@ -304,14 +303,24 @@ class FirExpectActualMatchingContextImpl private constructor(
override val TypeParameterSymbolMarker.isReified: Boolean
get() = asSymbol().isReified
// Copy-pasted to org.jetbrains.kotlin.fir.types.ExpectActualUtilsKt.areCompatibleExpectActualTypes
override fun areCompatibleExpectActualTypes(
expectType: KotlinTypeMarker?,
actualType: KotlinTypeMarker?,
parameterOfAnnotationComparisonMode: Boolean,
dynamicTypesEqualToAnything: Boolean
): Boolean {
if (expectType == null) return actualType == null
if (actualType == null) return false
if (!dynamicTypesEqualToAnything) {
val isExpectedDynamic = expectType is ConeDynamicType
val isActualDynamic = actualType is ConeDynamicType
if (isExpectedDynamic && !isActualDynamic || !isExpectedDynamic && isActualDynamic) {
return false
}
}
if (parameterOfAnnotationComparisonMode && expectType is ConeClassLikeType && expectType.isArrayType &&
actualType is ConeClassLikeType && actualType.isArrayType
) {
@@ -323,7 +332,7 @@ class FirExpectActualMatchingContextImpl private constructor(
}
return AbstractTypeChecker.equalTypes(
createTypeCheckerState(),
actualSession.typeContext,
expectType,
actualType
)
@@ -338,6 +338,7 @@ internal abstract class IrExpectActualMatchingContext(
expectType: KotlinTypeMarker?,
actualType: KotlinTypeMarker?,
parameterOfAnnotationComparisonMode: Boolean,
dynamicTypesEqualToAnything: Boolean
): Boolean {
if (expectType == null) return actualType == null
if (actualType == null) return false
@@ -372,7 +372,8 @@ object AbstractExpectActualChecker {
if (!areCompatibleExpectActualTypes(
substitutor.safeSubstitute(expectDeclaration.returnType),
actualDeclaration.returnType,
parameterOfAnnotationComparisonMode = insideAnnotationClass
parameterOfAnnotationComparisonMode = insideAnnotationClass,
dynamicTypesEqualToAnything = false
)
) {
return ExpectActualCheckingCompatibility.ReturnType
@@ -147,6 +147,7 @@ interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemC
expectType: KotlinTypeMarker?,
actualType: KotlinTypeMarker?,
parameterOfAnnotationComparisonMode: Boolean = false,
dynamicTypesEqualToAnything: Boolean = true
): Boolean
fun actualTypeIsSubtypeOfExpectType(
@@ -7,4 +7,4 @@ annotation class Ann
// MODULE: m1-jvm()()(m1-common)
// FILE: jvm.kt
actual fun <T : <!UNRESOLVED_REFERENCE!>Unresolved<!>> foo() {}
actual fun <T : <!UNRESOLVED_REFERENCE!>Unresolved<!>> <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}