Add 'Covariant equals' inspection

#KT-29798 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-03-08 18:25:14 +09:00
committed by Dmitry Gridin
parent 3998e842f1
commit 61f3e776a7
15 changed files with 209 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.KotlinCovariantEqualsInspection
@@ -0,0 +1,7 @@
// PROBLEM: 'equals' should take 'Any?' as its argument
// FIX: none
class Foo {
fun <caret>equals(other: Foo?): Boolean {
return true
}
}
@@ -0,0 +1,10 @@
// PROBLEM: none
class Foo {
fun <caret>equals(other: Foo?): Boolean {
return true
}
override fun equals(other: Any?): Boolean {
return true
}
}
@@ -0,0 +1,8 @@
// PROBLEM: none
class F {
companion object {
fun <caret>equals(other: F?): Boolean {
return true
}
}
}
@@ -0,0 +1,7 @@
// PROBLEM: 'equals' should take 'Any?' as its argument
// FIX: none
object F {
fun <caret>equals(other: F?): Boolean {
return true
}
}
@@ -0,0 +1,9 @@
// PROBLEM: 'equals' should take 'Any?' as its argument
// FIX: none
interface F
val f = object : F {
fun <caret>equals(other: F?): Boolean {
return true
}
}
@@ -0,0 +1,9 @@
// PROBLEM: none
class Foo {
fun test() {
fun <caret>equals(other: Foo?): Boolean {
return true
}
equals(null)
}
}
@@ -0,0 +1,13 @@
// PROBLEM: 'equals' should take 'Any?' as its argument
// FIX: none
open class Foo {
open fun equals(other: Foo?): Boolean {
return true
}
}
class Bar : Foo() {
override fun <caret>equals(other: Foo?): Boolean {
return true
}
}
@@ -0,0 +1,6 @@
// PROBLEM: none
class Foo {
override fun <caret>equals(other: Any?): Boolean {
return true
}
}
@@ -0,0 +1,4 @@
// PROBLEM: none
fun <caret>equals(other: Any?): Boolean {
return true
}
@@ -0,0 +1,6 @@
// PROBLEM: none
class Foo {
fun <caret>equals(other: Foo?, other2: Foo?): Boolean {
return true
}
}