[FIR] Fix processing constructors of sealed classes
- Allow declaring protected constructors in sealed classes - Make default visibility of sealed class constructor `protected` KT-44861 KT-44865
This commit is contained in:
committed by
TeamCityServer
parent
7c61ddc72b
commit
2d5b685535
@@ -37,4 +37,4 @@ package bar
|
||||
|
||||
import foo.Base
|
||||
|
||||
class E : <!HIDDEN, SEALED_SUPERTYPE!>Base<!>()
|
||||
class E : <!SEALED_SUPERTYPE!>Base<!>()
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,4 +14,4 @@ class A : Base()
|
||||
|
||||
package a
|
||||
|
||||
class B : <!HIDDEN!>Base<!>()
|
||||
class B : Base()
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
// ISSUE: KT-44861
|
||||
// DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
sealed class Foo() {
|
||||
class A : Foo()
|
||||
class B : Foo()
|
||||
}
|
||||
|
||||
fun Foo(kind: String = "A"): Foo = when (kind) {
|
||||
"A" -> Foo.A()
|
||||
"B" -> Foo.B()
|
||||
else -> throw Exception()
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val foo = <!SEALED_CLASS_CONSTRUCTOR_CALL!>Foo<!>()
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// ISSUE: KT-44861
|
||||
// DIAGNOSTICS: -UNUSED_VARIABLE
|
||||
|
||||
|
||||
+9
-9
@@ -2,21 +2,21 @@
|
||||
// DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
sealed class Case1(val x: Int) {
|
||||
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
|
||||
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)<!>
|
||||
sealed class Case2 protected constructor(val x: Int) {
|
||||
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)<!>
|
||||
protected constructor(s: String) : this(s.length)
|
||||
|
||||
class Inheritor1 : Case3(10) // should OK
|
||||
class Inheritor2 : Case3("Hello")
|
||||
@@ -25,8 +25,8 @@ sealed class Case3 private constructor(val x: Int) {
|
||||
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)<!>
|
||||
protected constructor(x: Int)
|
||||
protected constructor(s: String) : this(s.length)
|
||||
|
||||
class Inheritor1 : Case4(10)
|
||||
class Inheritor2 : Case4("Hello")
|
||||
@@ -34,8 +34,8 @@ sealed class Case4 {
|
||||
|
||||
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()<!>
|
||||
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()
|
||||
}
|
||||
|
||||
+9
-9
@@ -2,21 +2,21 @@
|
||||
// DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
sealed class Case1(val x: Int) {
|
||||
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
|
||||
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)<!>
|
||||
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) {
|
||||
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(s: String) : this(s.length)<!>
|
||||
protected constructor(s: String) : this(s.length)
|
||||
|
||||
class Inheritor1 : Case3(10) // should OK
|
||||
class Inheritor2 : Case3("Hello")
|
||||
@@ -25,8 +25,8 @@ sealed class Case3 private constructor(val x: Int) {
|
||||
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)<!>
|
||||
protected constructor(x: Int)
|
||||
protected constructor(s: String) : this(s.length)
|
||||
|
||||
class Inheritor1 : Case4(10)
|
||||
class Inheritor2 : Case4("Hello")
|
||||
@@ -34,8 +34,8 @@ sealed class Case4 {
|
||||
|
||||
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()<!>
|
||||
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()
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@ val test3a = <!HIDDEN!>EnumClass<!>()
|
||||
|
||||
sealed class SealedClass
|
||||
typealias Test4 = SealedClass
|
||||
val test4 = <!SEALED_CLASS_CONSTRUCTOR_CALL!>Test4<!>()
|
||||
val test4a = <!SEALED_CLASS_CONSTRUCTOR_CALL!>SealedClass<!>()
|
||||
val test4 = <!HIDDEN!>Test4<!>()
|
||||
val test4a = <!HIDDEN!>SealedClass<!>()
|
||||
|
||||
class Outer {
|
||||
inner class Inner
|
||||
|
||||
Reference in New Issue
Block a user