[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:
@@ -30,6 +30,7 @@ fun createExpectActualTypeParameterSubstitutor(
|
|||||||
return substitutor.chain(parentSubstitutor)
|
return substitutor.chain(parentSubstitutor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Copy-pasted to org.jetbrains.kotlin.fir.resolve.transformers.mpp.FirExpectActualMatchingContextImpl.areCompatibleExpectActualTypes
|
||||||
fun areCompatibleExpectActualTypes(
|
fun areCompatibleExpectActualTypes(
|
||||||
expectedType: ConeKotlinType?,
|
expectedType: ConeKotlinType?,
|
||||||
actualType: ConeKotlinType?,
|
actualType: ConeKotlinType?,
|
||||||
|
|||||||
+11
-2
@@ -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
|
||||||
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext.AnnotationCallInfo
|
import org.jetbrains.kotlin.resolve.calls.mpp.ExpectActualMatchingContext.AnnotationCallInfo
|
||||||
import org.jetbrains.kotlin.resolve.checkers.OptInNames
|
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.resolve.multiplatform.ExpectActualMatchingCompatibility
|
||||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||||
import org.jetbrains.kotlin.types.TypeCheckerState
|
import org.jetbrains.kotlin.types.TypeCheckerState
|
||||||
@@ -304,14 +303,24 @@ class FirExpectActualMatchingContextImpl private constructor(
|
|||||||
override val TypeParameterSymbolMarker.isReified: Boolean
|
override val TypeParameterSymbolMarker.isReified: Boolean
|
||||||
get() = asSymbol().isReified
|
get() = asSymbol().isReified
|
||||||
|
|
||||||
|
// Copy-pasted to org.jetbrains.kotlin.fir.types.ExpectActualUtilsKt.areCompatibleExpectActualTypes
|
||||||
override fun areCompatibleExpectActualTypes(
|
override fun areCompatibleExpectActualTypes(
|
||||||
expectType: KotlinTypeMarker?,
|
expectType: KotlinTypeMarker?,
|
||||||
actualType: KotlinTypeMarker?,
|
actualType: KotlinTypeMarker?,
|
||||||
parameterOfAnnotationComparisonMode: Boolean,
|
parameterOfAnnotationComparisonMode: Boolean,
|
||||||
|
dynamicTypesEqualToAnything: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (expectType == null) return actualType == null
|
if (expectType == null) return actualType == null
|
||||||
if (actualType == null) return false
|
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 &&
|
if (parameterOfAnnotationComparisonMode && expectType is ConeClassLikeType && expectType.isArrayType &&
|
||||||
actualType is ConeClassLikeType && actualType.isArrayType
|
actualType is ConeClassLikeType && actualType.isArrayType
|
||||||
) {
|
) {
|
||||||
@@ -323,7 +332,7 @@ class FirExpectActualMatchingContextImpl private constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return AbstractTypeChecker.equalTypes(
|
return AbstractTypeChecker.equalTypes(
|
||||||
createTypeCheckerState(),
|
actualSession.typeContext,
|
||||||
expectType,
|
expectType,
|
||||||
actualType
|
actualType
|
||||||
)
|
)
|
||||||
|
|||||||
+1
@@ -338,6 +338,7 @@ internal abstract class IrExpectActualMatchingContext(
|
|||||||
expectType: KotlinTypeMarker?,
|
expectType: KotlinTypeMarker?,
|
||||||
actualType: KotlinTypeMarker?,
|
actualType: KotlinTypeMarker?,
|
||||||
parameterOfAnnotationComparisonMode: Boolean,
|
parameterOfAnnotationComparisonMode: Boolean,
|
||||||
|
dynamicTypesEqualToAnything: Boolean
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (expectType == null) return actualType == null
|
if (expectType == null) return actualType == null
|
||||||
if (actualType == null) return false
|
if (actualType == null) return false
|
||||||
|
|||||||
+2
-1
@@ -372,7 +372,8 @@ object AbstractExpectActualChecker {
|
|||||||
if (!areCompatibleExpectActualTypes(
|
if (!areCompatibleExpectActualTypes(
|
||||||
substitutor.safeSubstitute(expectDeclaration.returnType),
|
substitutor.safeSubstitute(expectDeclaration.returnType),
|
||||||
actualDeclaration.returnType,
|
actualDeclaration.returnType,
|
||||||
parameterOfAnnotationComparisonMode = insideAnnotationClass
|
parameterOfAnnotationComparisonMode = insideAnnotationClass,
|
||||||
|
dynamicTypesEqualToAnything = false
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
return ExpectActualCheckingCompatibility.ReturnType
|
return ExpectActualCheckingCompatibility.ReturnType
|
||||||
|
|||||||
+1
@@ -147,6 +147,7 @@ interface ExpectActualMatchingContext<T : DeclarationSymbolMarker> : TypeSystemC
|
|||||||
expectType: KotlinTypeMarker?,
|
expectType: KotlinTypeMarker?,
|
||||||
actualType: KotlinTypeMarker?,
|
actualType: KotlinTypeMarker?,
|
||||||
parameterOfAnnotationComparisonMode: Boolean = false,
|
parameterOfAnnotationComparisonMode: Boolean = false,
|
||||||
|
dynamicTypesEqualToAnything: Boolean = true
|
||||||
): Boolean
|
): Boolean
|
||||||
|
|
||||||
fun actualTypeIsSubtypeOfExpectType(
|
fun actualTypeIsSubtypeOfExpectType(
|
||||||
|
|||||||
+1
-1
@@ -7,4 +7,4 @@ annotation class Ann
|
|||||||
|
|
||||||
// MODULE: m1-jvm()()(m1-common)
|
// MODULE: m1-jvm()()(m1-common)
|
||||||
// FILE: jvm.kt
|
// FILE: jvm.kt
|
||||||
actual fun <T : <!UNRESOLVED_REFERENCE!>Unresolved<!>> foo() {}
|
actual fun <T : <!UNRESOLVED_REFERENCE!>Unresolved<!>> <!ACTUAL_WITHOUT_EXPECT!>foo<!>() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user