Fix problems with 'dynamic'
diff --git a/compiler/fir/analysis-tests/testData/resolve/problematicEquals.kt b/compiler/fir/analysis-tests/testData/resolve/problematicEquals.kt index bb8e8c8..162f649 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problematicEquals.kt +++ b/compiler/fir/analysis-tests/testData/resolve/problematicEquals.kt
@@ -1,4 +1,5 @@ -// RUN_PIPELINE_TILL: BACKEND +// RUN_PIPELINE_TILL: FRONTEND +// DIAGNOSTICS: -UNSUPPORTED data class A(val name: String) data class B(val name: String) @@ -27,5 +28,8 @@ return true } +fun test5a(a: A, b: dynamic): Boolean = a == b +fun test5b(a: dynamic, b: A): Boolean = a == b + /* GENERATED_FIR_TAGS: andExpression, classDeclaration, data, equalityExpression, functionDeclaration, ifExpression, isExpression, localProperty, nullableType, primaryConstructor, propertyDeclaration, smartcast */
diff --git a/compiler/fir/analysis-tests/testData/resolve/problematicEqualsCollections.kt b/compiler/fir/analysis-tests/testData/resolve/problematicEqualsCollections.kt index f4a533d..f7e24ab 100644 --- a/compiler/fir/analysis-tests/testData/resolve/problematicEqualsCollections.kt +++ b/compiler/fir/analysis-tests/testData/resolve/problematicEqualsCollections.kt
@@ -1,4 +1,5 @@ -// RUN_PIPELINE_TILL: BACKEND +// RUN_PIPELINE_TILL: FRONTEND +// DIAGNOSTICS: -UNSUPPORTED fun test1(a: List<Int>, b: Set<Int>): Boolean = <!PROBLEMATIC_EQUALS!>a == b<!> fun test2(a: Set<Int>, b: List<Int>): Boolean = <!PROBLEMATIC_EQUALS!>a == b<!> @@ -7,5 +8,6 @@ fun test5(a: List<Int>, b: ArrayList<Int>): Boolean = a == b fun test6(a: HashSet<Int>, b: Set<Int>): Boolean = a == b fun test7(a: HashSet<Int>, b: LinkedHashSet<Int>): Boolean = a == b +fun test8(a: List<Int>, b: dynamic): Boolean = a == b /* GENERATED_FIR_TAGS: equalityExpression, functionDeclaration */
diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt index 8458466..262ca93 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirEqualityCompatibilityChecker.kt
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.StandardClassIds +import org.jetbrains.kotlin.types.model.isDynamic import org.jetbrains.kotlin.util.OperatorNameConventions object FirEqualityCompatibilityChecker : FirEqualityOperatorCallChecker(MppCheckerKind.Common) { @@ -98,6 +99,7 @@ context(context: CheckerContext) fun TypeInfo.approximateIfCollection(): TypeInfo { + if (directType.isDynamic()) return this for (specialCollectionType in specialCollectionTypes) { val symbol = specialCollectionType.toSymbol() as? FirClassSymbol<*> ?: continue val starProjectedType = symbol.constructStarProjectedType() @@ -110,6 +112,9 @@ } context(context: CheckerContext) + fun ConeKotlinType.isDynamic(): Boolean = with(context.session.typeContext) { this@isDynamic.isDynamic() } + + context(context: CheckerContext) fun checkStrictEqualityCase(leftTypeInfo: TypeInfo, rightTypeInfo: TypeInfo): ConeKotlinType? { val leftType = leftTypeInfo.type val leftCanBeNull = leftType.canBeNull(context.session) @@ -118,6 +123,7 @@ val rightCanBeNull = rightType.canBeNull(context.session) if (leftCanBeNull && rightCanBeNull) return null + if (leftType.isDynamic() || rightType.isDynamic()) return null if (areRelated(leftTypeInfo, rightTypeInfo)) return null fun problematicCase(strictness: EqualityStrictness, otherCanBeNull: Boolean): Boolean =
diff --git a/compiler/tests/org/jetbrains/kotlin/util/ArgsToParamsMatchingTest.kt b/compiler/tests/org/jetbrains/kotlin/util/ArgsToParamsMatchingTest.kt index b0b4aed..7668453 100644 --- a/compiler/tests/org/jetbrains/kotlin/util/ArgsToParamsMatchingTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/util/ArgsToParamsMatchingTest.kt
@@ -158,7 +158,7 @@ Assert.assertNotNull(actuals) val stringifiedActuals = actuals!!.mapKeys { it.key.name } val mappedExpected = expected.toMap() - if (expected != stringifiedActuals) { + if (mappedExpected != stringifiedActuals) { Assert.assertEquals(stringifiedActuals.keys, mappedExpected.keys) mappedExpected.forEach { exp -> val actVal = stringifiedActuals[exp.key]