[FIR] Add diagnostic CONFLICTING_OVERLOADS & REDECLARATION

This commit is contained in:
Nick
2020-08-05 09:35:10 +03:00
parent 36984009e9
commit 4669e019d1
72 changed files with 681 additions and 247 deletions
@@ -2,15 +2,15 @@
@Target(AnnotationTarget.CLASS)
annotation class Ann
var x: Int
<!REDECLARATION!>var x: Int
get() = 1
set(@Ann private x) { }
set(@Ann private x) { }<!>
var x: String = ""
<!REDECLARATION!>var x: String = ""
set(param: <!REDUNDANT_SETTER_PARAMETER_TYPE!>String<!>) {
field = "$param "
}
}<!>
class My {
var y: Int = 1
@@ -11,11 +11,11 @@ internal inline fun internal() {
f()
}
class C {
<!REDECLARATION!>class C {
internal val z = object {
fun foo() = 13
}
}
}<!>
class Foo2<
T1,
@@ -27,12 +27,12 @@ class Foo2<
internal inner class B<T,T2,>
}
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> class C {
<!REDECLARATION!><!REDUNDANT_VISIBILITY_MODIFIER!>public<!> class C {
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> val foo: Int = 0
<!REDUNDANT_VISIBILITY_MODIFIER!>public<!> fun bar() {}
}
}<!>
open class D {
protected open fun willRemainProtected() {
@@ -17,7 +17,7 @@ class LocalFreezableVar<T>(private var value: T) {
}
class C
<!REDECLARATION!>class C<!>
operator fun C.plus(a: Any): C = this
operator fun C.plusAssign(a: Any) {}
@@ -172,14 +172,14 @@ fun notAssignedWhenNotUsed(p: Int) {
var global = 1
class C {
<!REDECLARATION!>class C {
var field = 2
fun foo() {
print(field)
print(global)
}
}
}<!>
fun withDelegate() {
var s: String by Delegates.notNull()
@@ -0,0 +1,68 @@
<!CONFLICTING_OVERLOADS!>fun test(x: Int) {}<!>
<!CONFLICTING_OVERLOADS!>fun test(y: Int) {}<!>
fun test() {}
fun test(z: Int, c: Char) {}
<!REDECLARATION!>open class A {
open fun rest(s: String) {}
open val u = 20
}<!>
<!REDECLARATION!>class A {
}<!>
<!REDECLARATION!>class B : A {
<!CONFLICTING_OVERLOADS!>override fun rest(s: String) {}<!>
<!CONFLICTING_OVERLOADS!>fun rest(s: String) {}<!>
fun rest(l: Long) {}
override val u = 310
}<!>
<!REDECLARATION!>interface B<!>
<!REDECLARATION!>enum class B<!>
<!REDECLARATION!>val u = 10<!>
<!REDECLARATION!>val u = 20<!>
<!REDECLARATION!>typealias TA = A<!>
<!REDECLARATION!>typealias TA = B<!>
typealias BA = A
fun <T> kek(t: T) where T : (String) -> Any?, T : Char {}
fun <T> kek(t: T) where T : () -> Boolean, T : String {}
fun <T : Int> kek(t: T) {}
fun lol(a: Array<Int>) {}
fun lol(a: Array<Boolean>) {}
<!CONFLICTING_OVERLOADS!>fun <T> mem(t: T) where T : () -> Boolean, T : String {}<!>
<!CONFLICTING_OVERLOADS!>fun <T> mem(t: T) where T : String, T : () -> Boolean {}<!>
class M {
companion <!REDECLARATION!>object<!> {}
<!REDECLARATION!>val Companion = object : Any {}<!>
}
fun B.foo() {}
class L {
fun B.foo() {}
}
fun mest()
class mest
fun() {}
private fun() {}
@@ -0,0 +1,124 @@
FILE: conflictingOverloads.kt
public final fun test(x: R|kotlin/Int|): R|kotlin/Unit| {
}
public final fun test(y: R|kotlin/Int|): R|kotlin/Unit| {
}
public final fun test(): R|kotlin/Unit| {
}
public final fun test(z: R|kotlin/Int|, c: R|kotlin/Char|): R|kotlin/Unit| {
}
public open class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
public open fun rest(s: R|kotlin/String|): R|kotlin/Unit| {
}
public open val u: R|kotlin/Int| = Int(20)
public get(): R|kotlin/Int|
}
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
}
public final class B : R|A| {
public constructor(): R|B| {
super<R|A|>()
}
public final override fun rest(s: R|kotlin/String|): R|kotlin/Unit| {
}
public final fun rest(s: R|kotlin/String|): R|kotlin/Unit| {
}
public final fun rest(l: R|kotlin/Long|): R|kotlin/Unit| {
}
public final override val u: R|kotlin/Int| = Int(310)
public get(): R|kotlin/Int|
}
public abstract interface B : R|kotlin/Any| {
}
public final enum class B : R|kotlin/Enum<B>| {
private constructor(): R|B| {
super<R|kotlin/Enum<B>|>()
}
public final static fun values(): R|kotlin/Array<B>| {
}
public final static fun valueOf(value: R|kotlin/String|): R|B| {
}
}
public final val u: R|kotlin/Int| = Int(10)
public get(): R|kotlin/Int|
public final val u: R|kotlin/Int| = Int(20)
public get(): R|kotlin/Int|
public final typealias TA = R|A|
public final typealias TA = R|B|
public final typealias BA = R|A|
public final fun <T : R|(kotlin/String) -> kotlin/Any?|, R|kotlin/Char|> kek(t: R|T|): R|kotlin/Unit| {
}
public final fun <T : R|() -> kotlin/Boolean|, R|kotlin/String|> kek(t: R|T|): R|kotlin/Unit| {
}
public final fun <T : R|kotlin/Int|> kek(t: R|T|): R|kotlin/Unit| {
}
public final fun lol(a: R|kotlin/Array<kotlin/Int>|): R|kotlin/Unit| {
}
public final fun lol(a: R|kotlin/Array<kotlin/Boolean>|): R|kotlin/Unit| {
}
public final fun <T : R|() -> kotlin/Boolean|, R|kotlin/String|> mem(t: R|T|): R|kotlin/Unit| {
}
public final fun <T : R|kotlin/String|, R|() -> kotlin/Boolean|> mem(t: R|T|): R|kotlin/Unit| {
}
public final class M : R|kotlin/Any| {
public constructor(): R|M| {
super<R|kotlin/Any|>()
}
public final companion object Companion : R|kotlin/Any| {
private constructor(): R|M.Companion| {
super<R|kotlin/Any|>()
}
}
public final val Companion: R|<anonymous>| = object : R|kotlin/Any| {
private constructor(): R|<anonymous>| {
super<R|kotlin/Any|>()
}
}
public get(): R|<anonymous>|
}
public final fun R|B|.foo(): R|kotlin/Unit| {
}
public final class L : R|kotlin/Any| {
public constructor(): R|L| {
super<R|kotlin/Any|>()
}
public final fun R|B|.foo(): R|kotlin/Unit| {
}
}
public final fun mest(): R|kotlin/Unit|
public final class mest : R|kotlin/Any| {
public constructor(): R|mest| {
super<R|kotlin/Any|>()
}
}
public final fun <no name provided>(): R|kotlin/Unit| {
}
private final fun <no name provided>(): R|kotlin/Unit| {
}
@@ -1,9 +1,9 @@
class A {
companion object {
companion <!REDECLARATION!>object<!> {
}
companion <!MANY_COMPANION_OBJECTS!>object<!> {
companion <!MANY_COMPANION_OBJECTS, REDECLARATION!>object<!> {
}
}
@@ -1,6 +1,6 @@
object A
<!REDECLARATION!>object A<!>
val A = 10
<!REDECLARATION!>val A = 10<!>
fun foo() = A
@@ -1,4 +1,4 @@
fun takeString(s: String) {}
<!CONFLICTING_OVERLOADS!>fun takeString(s: String) {}<!>
class Wrapper(val s: String?) {
fun withThis() {
@@ -11,4 +11,4 @@ class Wrapper(val s: String?) {
}
}
fun takeString(s: String) {}
<!CONFLICTING_OVERLOADS!>fun takeString(s: String) {}<!>
@@ -23,11 +23,11 @@ fun test_2(a: A?) {
}
}
fun test_3(x: Any?) {
<!CONFLICTING_OVERLOADS!>fun test_3(x: Any?) {
val a = x as? A ?: return
a.foo() // Should be OK
x.foo() // Should be OK
}
}<!>
// ----------------- Unstable -----------------
@@ -53,8 +53,8 @@ fun test_2(a: B?) {
}
}
fun test_3(x: Any?) {
<!CONFLICTING_OVERLOADS!>fun test_3(x: Any?) {
val a = x as? B ?: return
a.foo() // Should be OK
x.foo() // Should be OK
}
}<!>
+4 -4
View File
@@ -13,7 +13,7 @@ class B()
class C(val b : B)
fun get(f: Boolean) = if (f) {A.A1} else {""}
fun case2() {
<!CONFLICTING_OVERLOADS!>fun case2() {
val flag: Any = get(false) //string
val l1 = when (flag!!) { // should be NO_ELSE_IN_WHEN
@@ -25,9 +25,9 @@ fun case2() {
A.A1 -> B()
A.A2 -> B()
}
}
}<!>
fun case2() {
<!CONFLICTING_OVERLOADS!>fun case2() {
val flag: Any = get(true) //A
val l1 = when (flag!!) {// should be NO_ELSE_IN_WHEN
@@ -39,7 +39,7 @@ fun case2() {
A.A1 -> B()
A.A2 -> B()
}
}
}<!>
fun case3() {
@@ -1,5 +1,5 @@
fun bar(x: String): Int = 1
fun bar(x: String): Double = 1
<!CONFLICTING_OVERLOADS!>fun bar(x: String): Int = 1<!>
<!CONFLICTING_OVERLOADS!>fun bar(x: String): Double = 1<!>
fun baz(x: String): Int = 1
fun <T, R> foobaz(x: T): R = TODO()
@@ -1,8 +1,8 @@
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
<!CONFLICTING_OVERLOADS!>@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
<!HIDDEN!>@kotlin.internal.LowPriorityInOverloadResolution<!>
fun foo(): Int = 1
fun foo(): Int = 1<!>
fun foo(): String = ""
<!CONFLICTING_OVERLOADS!>fun foo(): String = ""<!>
fun test() {
val s = foo()
@@ -13,7 +13,7 @@ fun test() {
val Any.bar get() = "456"
val String.bar get() = "987"
val t = "".bar
<!REDECLARATION!>val t = "".bar<!>
val p = Pair(0, "")
@@ -21,4 +21,4 @@ class Base<T>(val x: T)
class Derived : Base<Int>(10)
val xx = Derived().x + 1
val t = throw AssertionError("")
<!REDECLARATION!>val t = throw AssertionError("")<!>