[FIR] Add diagnostic for constructor delegation cycles
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ class Foo {
|
||||
bar = ""
|
||||
}
|
||||
|
||||
constructor(a: Int) : this(a) {
|
||||
constructor(a: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(a) {
|
||||
bar = "a"
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -7,12 +7,12 @@ class Foo {
|
||||
bar = ""
|
||||
}
|
||||
|
||||
constructor(a: Int) : this(a, 0, 0) {
|
||||
constructor(a: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(a, 0, 0) {
|
||||
}
|
||||
|
||||
constructor(a: Int, b: Int) : this(a) {
|
||||
constructor(a: Int, b: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(a) {
|
||||
}
|
||||
|
||||
constructor(a: Int, b: Int, c: Int) : this(a, b) {
|
||||
constructor(a: Int, b: Int, c: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(a, b) {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ expect enum class En(x: Int) {
|
||||
E2(42),
|
||||
;
|
||||
|
||||
<!NONE_APPLICABLE!>constructor(s: String)<!>
|
||||
constructor(s: String)
|
||||
}
|
||||
|
||||
expect enum class En2 {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// FILE: common.kt
|
||||
|
||||
expect class Foo(zzz: Int) {
|
||||
<!NONE_APPLICABLE!>constructor(aaa: Boolean)<!>
|
||||
constructor(aaa: Boolean)
|
||||
|
||||
fun f1(xxx: String): String
|
||||
}
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
object A {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||
init {}
|
||||
}
|
||||
|
||||
enum class B {
|
||||
X() {
|
||||
<!CONSTRUCTOR_IN_OBJECT, NONE_APPLICABLE!>constructor()<!>
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||
}
|
||||
}
|
||||
|
||||
val anonObject = object {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
object A {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||
init {}
|
||||
|
||||
+12
-12
@@ -1,33 +1,33 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class A1 {
|
||||
constructor(): this()
|
||||
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>()
|
||||
}
|
||||
|
||||
class A2(x: Byte) {
|
||||
constructor(x1: Int): this(x1, 1)
|
||||
constructor(x1: Int, x2: Int): this(x1, x2, 2)
|
||||
constructor(x1: Int, x2: Int, x3: Int): this(x1)
|
||||
constructor(x1: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1, 1)
|
||||
constructor(x1: Int, x2: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1, x2, 2)
|
||||
constructor(x1: Int, x2: Int, x3: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1)
|
||||
|
||||
// delegating to previously declared cycle
|
||||
constructor(x1: Double): this(1)
|
||||
constructor(x1: Double): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(1)
|
||||
|
||||
|
||||
// delegating to cycle declared after
|
||||
constructor(x1: String): this(1L)
|
||||
constructor(x1: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(1L)
|
||||
|
||||
constructor(x1: Long): this(x1, 1L)
|
||||
constructor(x1: Long, x2: Long): this(x1, x2, 2L)
|
||||
constructor(x1: Long, x2: Long, x3: Long): this(x1)
|
||||
constructor(x1: Long): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1, 1L)
|
||||
constructor(x1: Long, x2: Long): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1, x2, 2L)
|
||||
constructor(x1: Long, x2: Long, x3: Long): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1)
|
||||
|
||||
// no cycle, just call to primary constuctor
|
||||
constructor(x1: Double, x2: Double): this(x1, x2, 1.0)
|
||||
constructor(x1: Double, x2: Double, x3: Double): this(x1, x2, x3, 1.0)
|
||||
constructor(x1: Double, x2: Double, x3: Double, x4: Double): this(1.toByte())
|
||||
|
||||
constructor(): this("x", "y")
|
||||
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("x", "y")
|
||||
|
||||
constructor(x1: String, x2: String): this(x1, x2, "")
|
||||
constructor(x1: String, x2: String, x3: String): this(x1, x2)
|
||||
constructor(x1: String, x2: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1, x2, "")
|
||||
constructor(x1: String, x2: String, x3: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x1, x2)
|
||||
}
|
||||
|
||||
open class B(x: Byte)
|
||||
|
||||
@@ -17,5 +17,5 @@ class A1<R> : B<R> {
|
||||
}
|
||||
|
||||
class A2<R> {
|
||||
constructor(t: R, i: Int) : this(i, 1)
|
||||
constructor(t: R, i: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(i, 1)
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
open class B<R1, R2>(x: R1, y: R2)
|
||||
|
||||
class A0<T1, T2> {
|
||||
constructor(x: T1, y: T2): this(x, y)
|
||||
constructor(x: T1, y: T2): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, y)
|
||||
|
||||
constructor(x: T1, y: T2, z: T2): this(x, 1) // ok, delegates to constructor(x: T1, y: Int)
|
||||
constructor(x: T1, y: T2, z: T2): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, 1) // ok, delegates to constructor(x: T1, y: Int)
|
||||
|
||||
constructor(x: T1, y: Int): this(x, "")
|
||||
constructor(x: T1): this(x, 1)
|
||||
constructor(x: T1, y: T2, z: String): this(y, x)
|
||||
constructor(x: T1, y: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, "")
|
||||
constructor(x: T1): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, 1)
|
||||
constructor(x: T1, y: T2, z: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(y, x)
|
||||
}
|
||||
|
||||
class A1<T1, T2> : B<T1, T2> {
|
||||
|
||||
Vendored
+1
-1
@@ -2,6 +2,6 @@
|
||||
open class A(p1: String)
|
||||
|
||||
class B() : A("") {
|
||||
constructor(s: String) {
|
||||
<!INAPPLICABLE_CANDIDATE!>constructor(s: String)<!> {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
class X<T>(val t: T) {
|
||||
constructor(t: String): this(t)
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
class X<T>(val t: T) {
|
||||
constructor(t: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(t)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class X<T> {
|
||||
constructor(t: T, i: Int): this(i, 1)
|
||||
constructor(t: T, i: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(i, 1)
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,9 +1,9 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
class A(x: String = "", y: String = "") {
|
||||
constructor(x: String, y: String): this(x, y)
|
||||
constructor(): this("", "")
|
||||
constructor(): this("", "")
|
||||
constructor(x: String, y: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, y)
|
||||
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
|
||||
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
|
||||
}
|
||||
|
||||
class B {
|
||||
@@ -14,9 +14,9 @@ fun B(x: Int) {}
|
||||
|
||||
class Outer {
|
||||
class A(x: String = "", y: String = "") {
|
||||
constructor(x: String, y: String): this(x, y)
|
||||
constructor(): this("", "")
|
||||
constructor(): this("", "")
|
||||
constructor(x: String, y: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(x, y)
|
||||
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
|
||||
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>("", "")
|
||||
}
|
||||
|
||||
class B {
|
||||
|
||||
Reference in New Issue
Block a user