FIR: don't report EQUALITY_NOT_APPLICABLE for classes from java.*
Workaround for KT-48113
This commit is contained in:
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
FILE: IntersectionWithJavaString.kt
|
||||
public final fun collapse(path: R|kotlin/String|): R|kotlin/Unit| {
|
||||
lval result: R|ft<kotlin/String, kotlin/String?>| = (R|<local>/path| as R|java/lang/String|).R|java/lang/String.replace|(String(123), String(456))
|
||||
when () {
|
||||
!==(R|<local>/result|, R|<local>/path|) -> {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
// FULL_JDK
|
||||
fun collapse(path: String) {
|
||||
val result = (path as java.lang.String).replace("123", "456")
|
||||
if (<!EQUALITY_NOT_APPLICABLE_WARNING!>result !== path<!>) {}
|
||||
}
|
||||
+6
@@ -5045,6 +5045,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/EnumWithToString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IntersectionWithJavaString.kt")
|
||||
public void testIntersectionWithJavaString() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/IntersectionWithJavaString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UastPatterns.kt")
|
||||
public void testUastPatterns() throws Exception {
|
||||
|
||||
+6
@@ -5045,6 +5045,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/EnumWithToString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IntersectionWithJavaString.kt")
|
||||
public void testIntersectionWithJavaString() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/IntersectionWithJavaString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UastPatterns.kt")
|
||||
public void testUastPatterns() throws Exception {
|
||||
|
||||
+5
-4
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.StandardClassIds
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
@@ -212,10 +213,10 @@ internal object ConeTypeCompatibilityChecker {
|
||||
val classes = classesOrInterfaces.filter { !it.isInterface }
|
||||
// Java force single inheritance, so any pair of unrelated classes are incompatible.
|
||||
if (classes.size >= 2) {
|
||||
return if (classes.any { it.getHasPredefinedEqualityContract(this) }) {
|
||||
compatibilityUpperBound
|
||||
} else {
|
||||
Compatibility.SOFT_INCOMPATIBLE
|
||||
return when {
|
||||
classes.any { it.firClass.classId.packageFqName.startsWith(Name.identifier("java")) } -> Compatibility.SOFT_INCOMPATIBLE
|
||||
classes.any { it.getHasPredefinedEqualityContract(this) } -> compatibilityUpperBound
|
||||
else -> Compatibility.SOFT_INCOMPATIBLE
|
||||
}
|
||||
}
|
||||
val finalClass = classes.firstOrNull { it.isFinal } ?: return null
|
||||
|
||||
+6
@@ -5045,6 +5045,12 @@ public class DiagnosisCompilerFirTestdataTestGenerated extends AbstractDiagnosis
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/EnumWithToString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("IntersectionWithJavaString.kt")
|
||||
public void testIntersectionWithJavaString() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/intellij/IntersectionWithJavaString.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("UastPatterns.kt")
|
||||
public void testUastPatterns() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user