ConvertObjectToDataObjectInspection: fix "!is" case

^KTIJ-24348 Fixed

IJ-MR-101834

GitOrigin-RevId: 5ff6a9d8bc664facb0b0d738f779a07854926dd4
This commit is contained in:
Nikita Bobko
2023-01-25 14:49:10 +00:00
committed by intellij-monorepo-bot
parent f634e1c4d3
commit 965061ee55
3 changed files with 12 additions and 1 deletions
@@ -97,7 +97,7 @@ private fun KtExpression.tryUnwrapElvisOrDoubleBang(context: Lazy<BindingContext
private fun isCompatibleEquals(ktObject: KtObjectDeclaration, ktObjectFqn: Lazy<FqName>): Boolean =
when (val equals = ktObject.findEquals()) {
is Function -> ktObjectFqn.value == equals.function.singleExpressionBody()
?.asSafely<KtIsExpression>()?.typeReference?.let { typeReference ->
?.asSafely<KtIsExpression>()?.takeUnless(KtIsExpression::isNegated)?.typeReference?.let { typeReference ->
typeReference.analyze(BodyResolveMode.PARTIAL_NO_ADDITIONAL)[BindingContext.TYPE, typeReference]?.fqName
}
NonTrivialSuper -> false
@@ -4015,6 +4015,11 @@ public abstract class LocalInspectionTestGenerated extends AbstractLocalInspecti
runTest("testData/inspectionsLocal/convertObjectToDataObject/notCompatibleEquals.kt");
}
@TestMetadata("notCompatibleEquals2.kt")
public void testNotCompatibleEquals2() throws Exception {
runTest("testData/inspectionsLocal/convertObjectToDataObject/notCompatibleEquals2.kt");
}
@TestMetadata("notCompatibleInheritedEquals.kt")
public void testNotCompatibleInheritedEquals() throws Exception {
runTest("testData/inspectionsLocal/convertObjectToDataObject/notCompatibleInheritedEquals.kt");
@@ -0,0 +1,6 @@
// COMPILER_ARGUMENTS: -XXLanguage:+DataObjects
// PROBLEM: none
object<caret> Foo {
override fun toString(): String = "Foo"
override fun equals(other: Any?): Boolean = other !is Foo
}