[FE] Allow declaring protected constructors in sealed classes

#KT-44865 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-02-11 11:57:02 +03:00
committed by TeamCityServer
parent f3a8fcaea6
commit 7c61ddc72b
13 changed files with 447 additions and 8 deletions
@@ -1,7 +1,7 @@
sealed class Sealed <!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(val x: Int) {
sealed class Sealed protected constructor(val x: Int) {
object FIRST : Sealed()
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>public<!> constructor(): this(42)
<!NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED!>public<!> constructor(): this(42)
constructor(y: Int, z: Int): this(y + z)
}
@@ -0,0 +1,41 @@
// LANGUAGE: -AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed class Case1(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case1(10)
class Inheritor2 : Case1("Hello")
}
sealed class Case2 <!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(val x: Int)<!> {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case2(10)
class Inheritor2 : Case2("Hello")
}
sealed class Case3 private constructor(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case3(10) // should OK
class Inheritor2 : Case3("Hello")
}
class Case3Inheritor3 : <!INAPPLICABLE_CANDIDATE!>Case3<!>(20) // should be an error in 1.6 (?)
sealed class Case4 {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(x: Int)<!>
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case4(10)
class Inheritor2 : Case4("Hello")
}
sealed class Case5() {
private constructor(x: Int) : this()
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(x: Byte) : this()<!>
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>internal constructor(x: Short) : this()<!>
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>public constructor(x: Long) : this()<!>
constructor(x: Double) : this()
}
@@ -0,0 +1,41 @@
// LANGUAGE: -AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed class Case1(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(s: String) : this(s.length)
class Inheritor1 : Case1(10)
class Inheritor2 : Case1("Hello")
}
sealed class Case2 <!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(s: String) : this(s.length)
class Inheritor1 : Case2(10)
class Inheritor2 : Case2("Hello")
}
sealed class Case3 private constructor(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(s: String) : this(s.length)
class Inheritor1 : Case3(10) // should OK
class Inheritor2 : Case3("Hello")
}
class Case3Inheritor3 : Case3(20) // should be an error in 1.6 (?)
sealed class Case4 {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(x: Int)
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(s: String) : this(s.length)
class Inheritor1 : Case4(10)
class Inheritor2 : Case4("Hello")
}
sealed class Case5() {
private constructor(x: Int) : this()
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected<!> constructor(x: Byte) : this()
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>internal<!> constructor(x: Short) : this()
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>public<!> constructor(x: Long) : this()
constructor(x: Double) : this()
}
@@ -0,0 +1,119 @@
package
public sealed class Case1 {
private constructor Case1(/*0*/ x: kotlin.Int)
protected constructor Case1(/*0*/ s: kotlin.String)
public final val 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 Inheritor1 : Case1 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val 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 Inheritor2 : Case1 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val 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 sealed class Case2 {
protected constructor Case2(/*0*/ x: kotlin.Int)
protected constructor Case2(/*0*/ s: kotlin.String)
public final val 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 Inheritor1 : Case2 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val 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 Inheritor2 : Case2 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val 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 sealed class Case3 {
private constructor Case3(/*0*/ x: kotlin.Int)
protected constructor Case3(/*0*/ s: kotlin.String)
public final val 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 Inheritor1 : Case3 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val 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 Inheritor2 : Case3 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val 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 Case3Inheritor3 : Case3 {
public constructor Case3Inheritor3()
public final override /*1*/ /*fake_override*/ val 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 sealed class Case4 {
protected constructor Case4(/*0*/ x: kotlin.Int)
protected constructor Case4(/*0*/ s: kotlin.String)
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 Inheritor1 : Case4 {
public constructor Inheritor1()
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 Inheritor2 : Case4 {
public constructor Inheritor2()
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 sealed class Case5 {
private constructor Case5()
protected constructor Case5(/*0*/ x: kotlin.Byte)
private constructor Case5(/*0*/ x: kotlin.Double)
private constructor Case5(/*0*/ x: kotlin.Int)
public constructor Case5(/*0*/ x: kotlin.Long)
internal constructor Case5(/*0*/ x: kotlin.Short)
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
}
@@ -0,0 +1,41 @@
// LANGUAGE: +AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed class Case1(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case1(10)
class Inheritor2 : Case1("Hello")
}
sealed class Case2 <!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(val x: Int)<!> { // should be REDUNDANT_MODIFIER
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case2(10)
class Inheritor2 : Case2("Hello")
}
sealed class Case3 private constructor(val x: Int) {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case3(10) // should OK
class Inheritor2 : Case3("Hello")
}
class Case3Inheritor3 : <!INAPPLICABLE_CANDIDATE!>Case3<!>(20) // should be an error in 1.6 (?)
sealed class Case4 {
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(x: Int)<!>
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
class Inheritor1 : Case4(10)
class Inheritor2 : Case4("Hello")
}
sealed class Case5() {
private constructor(x: Int) : this()
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(x: Byte) : this()<!>
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>internal constructor(x: Short) : this()<!>
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>public constructor(x: Long) : this()<!>
constructor(x: Double) : this()
}
@@ -0,0 +1,41 @@
// LANGUAGE: +AllowSealedInheritorsInDifferentFilesOfSamePackage
// DIAGNOSTICS: -UNUSED_PARAMETER
sealed class Case1(val x: Int) {
protected constructor(s: String) : this(s.length)
class Inheritor1 : Case1(10)
class Inheritor2 : Case1("Hello")
}
sealed class Case2 protected constructor(val x: Int) { // should be REDUNDANT_MODIFIER
protected constructor(s: String) : this(s.length)
class Inheritor1 : Case2(10)
class Inheritor2 : Case2("Hello")
}
sealed class Case3 private constructor(val x: Int) {
protected constructor(s: String) : this(s.length)
class Inheritor1 : Case3(10) // should OK
class Inheritor2 : Case3("Hello")
}
class Case3Inheritor3 : Case3(20) // should be an error in 1.6 (?)
sealed class Case4 {
protected constructor(x: Int)
protected constructor(s: String) : this(s.length)
class Inheritor1 : Case4(10)
class Inheritor2 : Case4("Hello")
}
sealed class Case5() {
private constructor(x: Int) : this()
protected constructor(x: Byte) : this()
<!NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED!>internal<!> constructor(x: Short) : this()
<!NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED!>public<!> constructor(x: Long) : this()
constructor(x: Double) : this()
}
@@ -0,0 +1,119 @@
package
public sealed class Case1 {
protected constructor Case1(/*0*/ x: kotlin.Int)
protected constructor Case1(/*0*/ s: kotlin.String)
public final val 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 Inheritor1 : Case1 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val 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 Inheritor2 : Case1 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val 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 sealed class Case2 {
protected constructor Case2(/*0*/ x: kotlin.Int)
protected constructor Case2(/*0*/ s: kotlin.String)
public final val 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 Inheritor1 : Case2 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val 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 Inheritor2 : Case2 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val 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 sealed class Case3 {
private constructor Case3(/*0*/ x: kotlin.Int)
protected constructor Case3(/*0*/ s: kotlin.String)
public final val 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 Inheritor1 : Case3 {
public constructor Inheritor1()
public final override /*1*/ /*fake_override*/ val 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 Inheritor2 : Case3 {
public constructor Inheritor2()
public final override /*1*/ /*fake_override*/ val 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 Case3Inheritor3 : Case3 {
public constructor Case3Inheritor3()
public final override /*1*/ /*fake_override*/ val 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 sealed class Case4 {
protected constructor Case4(/*0*/ x: kotlin.Int)
protected constructor Case4(/*0*/ s: kotlin.String)
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 Inheritor1 : Case4 {
public constructor Inheritor1()
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 Inheritor2 : Case4 {
public constructor Inheritor2()
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 sealed class Case5 {
protected constructor Case5()
protected constructor Case5(/*0*/ x: kotlin.Byte)
protected constructor Case5(/*0*/ x: kotlin.Double)
private constructor Case5(/*0*/ x: kotlin.Int)
public constructor Case5(/*0*/ x: kotlin.Long)
internal constructor Case5(/*0*/ x: kotlin.Short)
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
}