Allow secondary constructors without body

#KT-6967 Fixed
This commit is contained in:
Denis Zharkov
2015-03-20 12:59:05 +03:00
parent 3f0541924f
commit 01e5ee718f
54 changed files with 390 additions and 153 deletions
@@ -1176,7 +1176,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
JetSecondaryConstructor constructor =
(JetSecondaryConstructor) DescriptorToSourceUtils.descriptorToDeclaration(constructorDescriptor);
assert constructor != null;
codegen.gen(constructor.getBodyExpression(), Type.VOID_TYPE);
if (constructor.hasBody()) {
codegen.gen(constructor.getBodyExpression(), Type.VOID_TYPE);
}
iv.visitInsn(RETURN);
}
@@ -908,7 +908,9 @@ public class JetParsing extends AbstractJetParsing {
emptyDelegationCall.done(CONSTRUCTOR_DELEGATION_CALL);
}
parseBlock();
if (at(LBRACE)) {
parseBlock();
}
}
private void parseThisOrSuper() {
@@ -88,7 +88,7 @@ public class JetSecondaryConstructor extends JetDeclarationStub<KotlinPlaceHolde
@Nullable
@Override
public JetExpression getBodyExpression() {
public JetBlockExpression getBodyExpression() {
return findChildByClass(JetBlockExpression.class);
}
@@ -105,7 +105,7 @@ public class JetSecondaryConstructor extends JetDeclarationStub<KotlinPlaceHolde
@Override
public boolean hasBody() {
return true;
return getBodyExpression() != null;
}
@Override
@@ -11,7 +11,7 @@ class A(val result: Int) {
object C {
}
constructor() : this(foo() + prop + B.bar() + B.prop + C) {}
constructor() : this(foo() + prop + B.bar() + B.prop + C)
}
fun box(): String {
@@ -1,13 +1,13 @@
open class A(val x: String = "abc", val y: String = "efg") {
constructor(x: String, y: String, z: Int): this(x, y + "#" + z.toString()) {}
constructor(x: String, y: String, z: Int): this(x, y + "#" + z.toString())
override fun toString() = "$x#$y"
}
class B : A {
constructor(x: String, y: String, z: Int): super(x, y + z.toString()) {}
constructor(x: String = "xyz", y: String = "123") : super(x, y) {}
constructor(x: Double): super(x.toString()) {}
constructor(x: String, y: String, z: Int): super(x, y + z.toString())
constructor(x: String = "xyz", y: String = "123") : super(x, y)
constructor(x: Double): super(x.toString())
}
fun box(): String {
@@ -9,7 +9,7 @@ class B : A {
val global = B()
class C(x: Int) : A by global {
constructor(): this(1) {}
constructor(): this(1)
}
fun box(): String {
@@ -1,11 +1,11 @@
open class B<T>(val x: T, val y: T) {
constructor(x: T): this(x, x) {}
constructor(x: T): this(x, x)
override fun toString() = "$x#$y"
}
class A : B<String> {
constructor(): super("default") {}
constructor(x: String): super(x, "default") {}
constructor(): super("default")
constructor(x: String): super(x, "default")
}
fun box(): String {
@@ -1,4 +1,4 @@
class A {
constructor() {}
constructor()
init {}
}
@@ -12,6 +12,6 @@ class A {
object C {
}
constructor(x: Int) {}
constructor() : this(foo() + prop + B.bar() + B.prop + C) {}
constructor(x: Int)
constructor() : this(foo() + prop + B.bar() + B.prop + C)
}
@@ -1,15 +1,15 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A(x: Int) {
constructor(x: Double): this(1) {}
constructor(x: String): this(1) {}
constructor(x: Double): this(1)
constructor(x: String): this(1)
}
val x1: A = A(1)
val x2: A = A(1.0)
val x3: A = A("abc")
class B<R> {
constructor(x: String) {}
constructor(x: R) {}
constructor(x: String)
constructor(x: R)
}
val y1: B<Int> = B(1)
@@ -1,20 +1,20 @@
object A {
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor() {}<!>
init {}
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
<!>init {}
}
enum class B {
X : B() {
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor() {}<!>
}
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
<!>}
}
class C {
companion object {
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor() {}<!>
}
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
<!>}
}
val anonObject = object {
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor() {}<!>
}
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
<!>}
@@ -1,3 +1,3 @@
trait A {
<!CONSTRUCTOR_IN_TRAIT!>constructor() {}<!>
}
<!CONSTRUCTOR_IN_TRAIT!>constructor()
<!>}
@@ -3,7 +3,7 @@ annotation class Ann1
annotation class Ann2(val x: Int)
class A {
Ann1 constructor() {}
<!NO_VALUE_FOR_PARAMETER!>Ann2<!> constructor(x1: Int) {}
Ann2(2) constructor(x1: Int, x2: Int) {}
Ann1 constructor()
<!NO_VALUE_FOR_PARAMETER!>Ann2<!> constructor(x1: Int)
Ann2(2) constructor(x1: Int, x2: Int)
}
@@ -1,39 +1,39 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A1 {
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>() {}
constructor(): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>()
}
class A2(x: Byte) {
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) {}
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): this(1)
// delegating to cycle declared after
constructor(x1: String): this(1L) {}
constructor(x1: String): this(1L)
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) {}
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(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(): this("x", "y")
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) {}
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)
class A : B {
// no cycle, just call to super 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): super(1.toByte()) {}
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): super(1.toByte())
}
@@ -1,12 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
data class A1(val x: String) {
constructor(): this("") {}
constructor(): this("")
}
data class A2() {
constructor(x: String): this() {}
constructor(x: String): this()
}
data class <!PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS!>A3<!> {
constructor() {}
constructor()
}
@@ -1,6 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A {
constructor(x: Any, y: Any, z: Any) {}
constructor(x: Any, y: Any, z: Any)
constructor(x: String?, y: String?): this(x!!, <!DEBUG_INFO_SMARTCAST!>x<!>.length().toString() + y!!, "") {
<!DEBUG_INFO_SMARTCAST!>x<!>.length() + <!DEBUG_INFO_SMARTCAST!>y<!>.length()
}
@@ -2,5 +2,5 @@ trait A
class AImpl : A
class B : <!UNSUPPORTED!>A by AImpl()<!> {
constructor() {}
constructor()
}
@@ -2,24 +2,24 @@
enum class A {
W: A(1) X: A(1, 2) Y: A(3.0) Z: A("") E: A()
constructor() {}
constructor(x: Int) {}
constructor(x: Int, y: Int): this(x+y) {}
constructor(x: Double): this(x.toInt(), 1) {}
constructor(x: String): <!DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR!>super<!>(x, 1) {}
constructor()
constructor(x: Int)
constructor(x: Int, y: Int): this(x+y)
constructor(x: Double): this(x.toInt(), 1)
constructor(x: String): <!DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR!>super<!>(x, 1)
}
enum class B(x: Int) {
W: B(1) X: B(1, 2) Y: B(3.0) Z: B("")
constructor(x: Int, y: Int): this(x+y) {}
constructor(x: Double): this(x.toInt(), 1) {}
constructor(x: String): <!DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR!>super<!>(x, 1) {}
constructor(x: Int, y: Int): this(x+y)
constructor(x: Double): this(x.toInt(), 1)
constructor(x: String): <!DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR!>super<!>(x, 1)
}
enum class C {
EMPTY: C() // may be we should avoid explicit call here
constructor() {}
constructor()
}
enum class D(val prop: Int) {
@@ -33,8 +33,8 @@ enum class D(val prop: Int) {
override fun f() = prop
}
constructor(): this(1) {}
constructor(x: String): this(x.length()) {}
constructor(): this(1)
constructor(x: String): this(x.length())
abstract fun f(): Int
}
@@ -1,8 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A(x: Int) {
<!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>constructor<!>() {}
<!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>constructor<!>()
}
open class B(x: Int)
class C(x: Int) : B(x) {
constructor(): <!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>super<!>(1) {}
constructor(): <!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>super<!>(1)
}
@@ -1,21 +1,21 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE
open class B<T>(x: T, y: T) {
constructor(x: T): this(x, x) {}
constructor(): this(null!!, null!!) {}
constructor(x: T): this(x, x)
constructor(): this(null!!, null!!)
}
class A0 : B<String?> {
constructor() {}
constructor(x: String): super(x) {}
constructor(x: String, y: String): super(x, y) {}
constructor()
constructor(x: String): super(x)
constructor(x: String, y: String): super(x, y)
}
class A1<R> : B<R> {
constructor() {}
constructor(x: R): super(x) {}
constructor(x: R, y: R): super(x, y) {}
constructor()
constructor(x: R): super(x)
constructor(x: R, y: R): super(x, y)
}
class A2<R> {
constructor(t: R, i: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(<!TYPE_MISMATCH!>i<!>, 1) {}
constructor(t: R, i: Int) : <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(<!TYPE_MISMATCH!>i<!>, 1)
}
@@ -2,25 +2,25 @@
open class B<R1, R2>(x: R1, y: R2)
class A0<T1, T2> {
constructor(x: T1, y: T2): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>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): this(x, 1) // ok, delegates to constructor(x: T1, y: Int)
constructor(x: T1, y: Int): <!NONE_APPLICABLE!>this<!>(x, "") {}
constructor(x: T1): this(x, 1) {}
constructor(x: T1, y: T2, z: String): <!NONE_APPLICABLE!>this<!>(y, x) {}
constructor(x: T1, y: Int): <!NONE_APPLICABLE!>this<!>(x, "")
constructor(x: T1): this(x, 1)
constructor(x: T1, y: T2, z: String): <!NONE_APPLICABLE!>this<!>(y, x)
}
class A1<T1, T2> : B<T1, T2> {
constructor(x: T1, y: T2): super(x, y) {}
constructor(x: T1, y: Int): super(x, <!TYPE_MISMATCH(T2; kotlin.Int)!>y<!>) {}
constructor(x: T1, y: T1, z: T1): super(x, <!TYPE_MISMATCH(T2; T1)!>y<!>) {}
constructor(x: T1, y: T2): super(x, y)
constructor(x: T1, y: Int): super(x, <!TYPE_MISMATCH(T2; kotlin.Int)!>y<!>)
constructor(x: T1, y: T1, z: T1): super(x, <!TYPE_MISMATCH(T2; T1)!>y<!>)
}
class A2<T1, T2> : B<T1, Int> {
constructor(x: T1, y: T2): super(x, <!TYPE_MISMATCH(kotlin.Int; T2)!>y<!>) {}
constructor(x: T1, y: Int): super(x, y) {}
constructor(x: T1, y: T1, z: T1): super(x, <!TYPE_MISMATCH(kotlin.Int; T1)!>y<!>) {}
constructor(x: T1, y: T2, z: String): super(<!TYPE_MISMATCH(T1; T2)!>y<!>, 1) {}
constructor(x: T1, y: T2): super(x, <!TYPE_MISMATCH(kotlin.Int; T2)!>y<!>)
constructor(x: T1, y: Int): super(x, y)
constructor(x: T1, y: T1, z: T1): super(x, <!TYPE_MISMATCH(kotlin.Int; T1)!>y<!>)
constructor(x: T1, y: T2, z: String): super(<!TYPE_MISMATCH(T1; T2)!>y<!>, 1)
}
@@ -1,16 +1,16 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class B<X, Y : X> {
constructor(x: X, y: Y) {}
constructor(x: X, s: String) {}
constructor(y: Y, i: Int) : this(y, "") {}
constructor(x: X, y: Y)
constructor(x: X, s: String)
constructor(y: Y, i: Int) : this(y, "")
}
class A<T1, T2 : T1> : B<T1, T2> {
constructor(x: T1, y: T2): super(x, y) {}
constructor(x: T2, y: T2, z: String): super(x, y) {}
constructor(x: T1, y: T2): super(x, y)
constructor(x: T2, y: T2, z: String): super(x, y)
constructor(x: T2, z: String, z1: String): super(x, "") {}
constructor(x: T2, z: String, z1: String, z2: String): super(x, 1) {}
constructor(x: T1, z: String, z1: String, z2: String, z3: String): super(x, "") {}
constructor(x: T1, z: String, z1: String, z2: String, z3: String, z4: String): <!NONE_APPLICABLE!>super<!>(x, 1) {}
constructor(x: T2, z: String, z1: String): super(x, "")
constructor(x: T2, z: String, z1: String, z2: String): super(x, 1)
constructor(x: T1, z: String, z1: String, z2: String, z3: String): super(x, "")
constructor(x: T1, z: String, z1: String, z2: String, z3: String, z4: String): <!NONE_APPLICABLE!>super<!>(x, 1)
}
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class B(x: Int)
class A : <!SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR!>B(1)<!> {
constructor(): super(1) {}
constructor(): super(1)
}
@@ -11,5 +11,5 @@ class A {
}
}
class A1(val x: Int, val y: Int) {
constructor(other: A1): this(other.x, other.y) {}
constructor(other: A1): this(other.x, other.y)
}
@@ -1,3 +1,3 @@
class X<T>(val t: T) {
constructor(t: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(t) {}
constructor(t: String): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(t)
}
@@ -1,5 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class X<T>(val t: T) {
constructor(t: T, i: Int) : <!NONE_APPLICABLE!>this<!>(i) {
}
constructor(t: T, i: Int) : <!NONE_APPLICABLE!>this<!>(i)
}
@@ -1,5 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class X<T> {
constructor(t: T, i: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(<!TYPE_MISMATCH!>i<!>, 1) { // no error
}
constructor(t: T, i: Int): <!CYCLIC_CONSTRUCTOR_DELEGATION_CALL!>this<!>(<!TYPE_MISMATCH!>i<!>, 1)
}
@@ -1,5 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A<T1, T2> {
constructor(block: (T1) -> T2) {}
constructor(x: T2): this({ x }) {}
constructor(block: (T1) -> T2)
constructor(x: T2): this({ x })
}
@@ -3,11 +3,11 @@ open class B(open val parentProperty: String)
class A : B {
val myProp: String = ""
override val parentProperty: String = ""
constructor(arg: String = <!UNRESOLVED_REFERENCE!>myProp<!>): super(<!UNRESOLVED_REFERENCE!>myProp<!>) {}
constructor(x1: String, arg: String = <!NO_THIS!>this<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>myProp<!>): super(<!NO_THIS!>this<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>myProp<!>) {}
constructor(x1: String, x2: String, arg: String = <!UNRESOLVED_REFERENCE!>parentProperty<!>): super(<!UNRESOLVED_REFERENCE!>parentProperty<!>) {}
constructor(x1: String, x2: String, x3: String, arg: String = <!SUPER_NOT_AVAILABLE!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>parentProperty<!>): super(<!SUPER_NOT_AVAILABLE!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>parentProperty<!>) {}
constructor(x1: String, x2: String, x3: String, x4: String, arg: String = foo(<!NO_THIS!>this<!>)): super(foo(<!NO_THIS!>this<!>)) {}
constructor(x1: String, x2: String, x3: String, x4: String, x5: String, arg: String = foo(this<!UNRESOLVED_REFERENCE!>@A<!>)): super(foo(this<!UNRESOLVED_REFERENCE!>@A<!>)) {}
constructor(arg: String = <!UNRESOLVED_REFERENCE!>myProp<!>): super(<!UNRESOLVED_REFERENCE!>myProp<!>)
constructor(x1: String, arg: String = <!NO_THIS!>this<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>myProp<!>): super(<!NO_THIS!>this<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>myProp<!>)
constructor(x1: String, x2: String, arg: String = <!UNRESOLVED_REFERENCE!>parentProperty<!>): super(<!UNRESOLVED_REFERENCE!>parentProperty<!>)
constructor(x1: String, x2: String, x3: String, arg: String = <!SUPER_NOT_AVAILABLE!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>parentProperty<!>): super(<!SUPER_NOT_AVAILABLE!>super<!>.<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>parentProperty<!>)
constructor(x1: String, x2: String, x3: String, x4: String, arg: String = foo(<!NO_THIS!>this<!>)): super(foo(<!NO_THIS!>this<!>))
constructor(x1: String, x2: String, x3: String, x4: String, x5: String, arg: String = foo(this<!UNRESOLVED_REFERENCE!>@A<!>)): super(foo(this<!UNRESOLVED_REFERENCE!>@A<!>))
}
fun foo(x: A) = ""
@@ -1,4 +1,4 @@
// do not report generate empty synthetic constructor by primary as it leads to CONFLICTING_JVM_DECLARATIONS
class A(val x: Int = 1, val y: Int = 2) {
constructor(): this(0, 0) {}
constructor(): this(0, 0)
}
@@ -1,8 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A {
constructor(x: Int) {
}
constructor(x: Int)
}
val x = A(<!NO_VALUE_FOR_PARAMETER!>)<!>
@@ -2,5 +2,5 @@ open class B
trait C
trait D
class A : C, B, D {
constructor() {}
constructor()
}
@@ -1,27 +1,26 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class <!CONFLICTING_OVERLOADS!>A(x: String = "", y: String = "")<!> {
<!CONFLICTING_OVERLOADS!>constructor(x: String, y: String)<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>(x, y) {}
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "") {}
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "") {}
<!CONFLICTING_OVERLOADS!>constructor(x: String, y: String)<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>(x, y)
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
}
class B {
<!CONFLICTING_OVERLOADS!>constructor(x: Int)<!> {}
<!CONFLICTING_OVERLOADS!>constructor(x: Int)<!>
}
<!CONFLICTING_OVERLOADS!>fun B(x: Int)<!> {}
class Outer {
class <!CONFLICTING_OVERLOADS!>A(x: String = "", y: String = "")<!> {
<!CONFLICTING_OVERLOADS!>constructor(x: String, y: String)<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>(x, y) {}
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "") {}
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "") {}
<!CONFLICTING_OVERLOADS!>constructor(x: String, y: String)<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>(x, y)
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
<!CONFLICTING_OVERLOADS!>constructor()<!>: <!OVERLOAD_RESOLUTION_AMBIGUITY!>this<!>("", "")
}
class B {
<!CONFLICTING_OVERLOADS!>constructor(x: Int)<!> {
}
<!CONFLICTING_OVERLOADS!>constructor(x: Int)<!>
}
<!CONFLICTING_OVERLOADS!>fun B(x: Int)<!> {}
@@ -1,11 +1,11 @@
class <!REDECLARATION!>A<!>
class <!REDECLARATION!>A<!> {
constructor() {}
constructor()
}
class B
class Outer {
class B {
constructor() {}
constructor()
}
}
@@ -1,4 +1,4 @@
class A {
val prop: Int = <!TYPE_MISMATCH!>""<!>
constructor() {}
constructor()
}
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
class A {
constructor(): super(<!TOO_MANY_ARGUMENTS!>1<!>) { }
constructor(): super(<!TOO_MANY_ARGUMENTS!>1<!>)
}
@@ -1,10 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class B(x: Double) {
constructor(x: Int): this(1.0) {}
constructor(x: String): this(1.0) {}
constructor(x: Int): this(1.0)
constructor(x: String): this(1.0)
}
trait C
class A : B, C {
constructor(): <!NONE_APPLICABLE!>super<!>(' ') { }
<!NONE_APPLICABLE!>constructor<!>(x: Int) { }
constructor(): <!NONE_APPLICABLE!>super<!>(' ')
<!NONE_APPLICABLE!>constructor<!>(x: Int)
}
@@ -3,5 +3,5 @@ class A {
constructor(
<!VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER!>val<!> x: Int, y: Int,
<!VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER!>var<!> z: Int,
<!ILLEGAL_MODIFIER!>public<!> a: Int) {}
<!ILLEGAL_MODIFIER!>public<!> a: Int)
}
@@ -2,11 +2,11 @@
fun <T> array(vararg x: T): Array<T> = null!!
open class B(vararg y: String) {
constructor(x: Int): this(x.toString(), *array("1"), "2") {}
constructor(x: Int): this(x.toString(), *array("1"), "2")
}
class A : B {
constructor(x: String, y: String): super(x, *array("3"), y) {}
constructor(x: String): super(x) {}
constructor(): super() {}
constructor(x: String, y: String): super(x, *array("3"), y)
constructor(x: String): super(x)
constructor(): super()
}
@@ -2,13 +2,13 @@
fun <T> array(vararg x: T): Array<T> = null!!
open class B(x: Int) {
constructor(vararg y: String): this(y[0].length()) {}
constructor(vararg y: String): this(y[0].length())
}
class A : B {
constructor(x: String, y: String): super(x, *array("q"), y) {}
constructor(x: String): super(x) {}
constructor(): super() {}
constructor(x: String, y: String): super(x, *array("q"), y)
constructor(x: String): super(x)
constructor(): super()
}
val b1 = B()
@@ -0,0 +1,10 @@
class A {
constructor()
fun foo() = 1
public constructor()
val x = 2
constructor(): this()
constructor(): super(3)
val x = 4
}
@@ -0,0 +1,97 @@
JetFile: emptyBody.kt
PACKAGE_DIRECTIVE
<empty list>
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('A')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
SECONDARY_CONSTRUCTOR
PsiElement(constructor)('constructor')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
CONSTRUCTOR_DELEGATION_CALL
CONSTRUCTOR_DELEGATION_REFERENCE
<empty list>
FUN
PsiElement(fun)('fun')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('foo')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
PsiWhiteSpace('\n ')
SECONDARY_CONSTRUCTOR
MODIFIER_LIST
PsiElement(public)('public')
PsiWhiteSpace(' ')
PsiElement(constructor)('constructor')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
CONSTRUCTOR_DELEGATION_CALL
CONSTRUCTOR_DELEGATION_REFERENCE
<empty list>
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('2')
PsiWhiteSpace('\n\n ')
SECONDARY_CONSTRUCTOR
PsiElement(constructor)('constructor')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
CONSTRUCTOR_DELEGATION_CALL
CONSTRUCTOR_DELEGATION_REFERENCE
PsiElement(this)('this')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
SECONDARY_CONSTRUCTOR
PsiElement(constructor)('constructor')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
CONSTRUCTOR_DELEGATION_CALL
CONSTRUCTOR_DELEGATION_REFERENCE
PsiElement(super)('super')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('3')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n ')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('x')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('4')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
@@ -5,6 +5,10 @@ class A {
fun foo() = 2
}
class C {
constructor(x: Int) : ()
}
class B {
constructor(x: Int) : () {
x = 3
@@ -62,6 +62,39 @@ JetFile: recoveryEmptyDelegationType.kt
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('C')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
SECONDARY_CONSTRUCTOR
PsiElement(constructor)('constructor')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('x')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
CONSTRUCTOR_DELEGATION_CALL
PsiErrorElement:Expecting a 'this' or 'super' constructor call
<empty list>
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
@@ -2,6 +2,11 @@ class A {
constructor : this() {}
val x: Int
}
class C {
constructor : this()
}
class B {
constructor : this() {}
}
@@ -39,7 +39,31 @@ JetFile: recoveryWithoutParameterList.kt
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n')
PsiWhiteSpace('\n\n')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('C')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
SECONDARY_CONSTRUCTOR
PsiElement(constructor)('constructor')
PsiErrorElement:Expecting '('
<empty list>
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
CONSTRUCTOR_DELEGATION_CALL
CONSTRUCTOR_DELEGATION_REFERENCE
PsiElement(this)('this')
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
@@ -2,3 +2,9 @@ class A {
constructor() : superr(1,2) {}
val x: Int
}
class B {
constructor() : thhiis(3, 4)
}
val x: Int = 1
@@ -47,4 +47,54 @@ JetFile: recoveryWrongDelegationName.kt
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
CLASS
PsiElement(class)('class')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('B')
PsiWhiteSpace(' ')
CLASS_BODY
PsiElement(LBRACE)('{')
PsiWhiteSpace('\n ')
SECONDARY_CONSTRUCTOR
PsiElement(constructor)('constructor')
VALUE_PARAMETER_LIST
PsiElement(LPAR)('(')
PsiElement(RPAR)(')')
PsiWhiteSpace(' ')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
CONSTRUCTOR_DELEGATION_CALL
PsiElement(IDENTIFIER)('thhiis')
PsiErrorElement:Expecting a 'this' or 'super' constructor call
<empty list>
VALUE_ARGUMENT_LIST
PsiElement(LPAR)('(')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('3')
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
VALUE_ARGUMENT
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('4')
PsiElement(RPAR)(')')
PsiWhiteSpace('\n')
PsiElement(RBRACE)('}')
PsiWhiteSpace('\n\n')
PROPERTY
PsiElement(val)('val')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('x')
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
TYPE_REFERENCE
USER_TYPE
REFERENCE_EXPRESSION
PsiElement(IDENTIFIER)('Int')
PsiWhiteSpace(' ')
PsiElement(EQ)('=')
PsiWhiteSpace(' ')
INTEGER_CONSTANT
PsiElement(INTEGER_LITERAL)('1')
@@ -1917,6 +1917,12 @@ public class JetParsingTestGenerated extends AbstractJetParsingTest {
doParsingTest(fileName);
}
@TestMetadata("emptyBody.kt")
public void testEmptyBody() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/secondaryConstructors/emptyBody.kt");
doParsingTest(fileName);
}
@TestMetadata("enumParsing.kt")
public void testEnumParsing() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/psi/secondaryConstructors/enumParsing.kt");
@@ -8,8 +8,7 @@ class A {
fun foo() {
}
constructor() {
}
constructor()
fun foo() {
}
@@ -55,8 +54,7 @@ class A {
constructor() : this() {
}
constructor() : this() {
}
constructor() : this()
constructor() : super() {
}
@@ -2,7 +2,7 @@ class A {
constructor() {}
constructor() {}
fun foo() {}
constructor() {}
constructor()
fun foo() {}
constructor() {}
val x = 1
@@ -26,6 +26,6 @@ constructor() {}
constructor() : this() {}
constructor():this() {}
constructor(): this () {}
constructor(): this ()
constructor(): super(){}
}
@@ -18,6 +18,8 @@ class A {
{
}
constructor()
constructor() {
}
}
@@ -22,6 +22,8 @@ class A
{
}
constructor()
constructor()
{
}
@@ -18,6 +18,7 @@ class A {
{}
constructor()
constructor() {
}
}