Prohibit protected constructor calls that are not super-calls in subtypes

#KT-11649 Fixed
This commit is contained in:
Denis Zharkov
2016-03-28 18:22:08 +03:00
parent 816f14a927
commit 92be4aee9c
12 changed files with 228 additions and 2 deletions
@@ -0,0 +1,26 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class A protected constructor(x: Int) {
protected constructor() : this(1)
public constructor(x: Double) : this(3)
}
class B4 : A(1) {
init {
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>()
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>(1)
A(5.0)
}
fun foo() {
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>()
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>(1)
A(5.0)
object : A() {}
object : A(1) {}
object : A(5.0) {}
class Local : A()
}
}
@@ -0,0 +1,18 @@
package
public open class A {
protected constructor A()
public constructor A(/*0*/ x: kotlin.Double)
protected constructor A(/*0*/ x: kotlin.Int)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class B4 : A {
public constructor B4()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,32 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: abc/A.java
package abc;
public class A {
protected A() {}
protected A(int x) {}
public A(double x) {}
}
// FILE: main.kt
import abc.*
class B4 : A(1) {
init {
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>()
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>(1)
A(5.0)
}
fun foo() {
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>()
<!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>A<!>(1)
A(5.0)
object : A() {}
object : A(1) {}
object : A(5.0) {}
class Local : A()
}
}
@@ -0,0 +1,9 @@
package
public final class B4 : abc.A {
public constructor B4()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,30 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// FILE: A.java
public class A {
protected A() {}
protected A(int x) {}
public A(double x) {}
}
// FILE: main.kt
class B4 : A(1) {
init {
A()
A(1)
A(5.0)
}
fun foo() {
A()
A(1)
A(5.0)
object : A() {}
object : A(1) {}
object : A(5.0) {}
class Local : A()
}
}
@@ -0,0 +1,18 @@
package
public open class A {
protected/*protected and package*/ constructor A()
public constructor A(/*0*/ x: kotlin.Double)
protected/*protected and package*/ constructor A(/*0*/ x: kotlin.Int)
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public final class B4 : A {
public constructor B4()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}