[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
+1
-1
@@ -12,7 +12,7 @@ public sealed class Sealed : R|kotlin/Any| {
|
||||
public final val z: R|test/Z|
|
||||
public get(): R|test/Z|
|
||||
|
||||
@R|test/Ann|() internal constructor(@R|test/Ann|() z: R|test/Z|): R|test/Sealed|
|
||||
@R|test/Ann|() protected constructor(@R|test/Ann|() z: R|test/Z|): R|test/Sealed|
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ public sealed class SealedClass : R|kotlin/Any| {
|
||||
|
||||
}
|
||||
|
||||
internal constructor(): R|test/SealedClass|
|
||||
protected constructor(): R|test/SealedClass|
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ FILE: constantValues.kt
|
||||
}
|
||||
|
||||
public sealed class Value : R|kotlin/Any| {
|
||||
private constructor(): R|KClassValue.Value| {
|
||||
protected constructor(): R|KClassValue.Value| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -30,13 +30,13 @@ FILE: incompatibleModifiers.kt
|
||||
|
||||
}
|
||||
public final class F : R|kotlin/Any| {
|
||||
private constructor(): R|F| {
|
||||
protected constructor(): R|F| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public sealed class G : R|kotlin/Any| {
|
||||
private constructor(): R|G| {
|
||||
protected constructor(): R|G| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ FILE: incompatibleModifiers.kt
|
||||
|
||||
}
|
||||
public sealed data class I : R|kotlin/Any| {
|
||||
private constructor(i: R|kotlin/Int|): R|I| {
|
||||
protected constructor(i: R|kotlin/Int|): R|I| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ FILE: incompatibleModifiers.kt
|
||||
}
|
||||
|
||||
public sealed inner class Z : R|kotlin/Any| {
|
||||
private constructor(): R|X.Z| {
|
||||
protected constructor(): R|X.Z| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ FILE: redundantModifier.kt
|
||||
|
||||
}
|
||||
public sealed class B : R|kotlin/Any| {
|
||||
private constructor(): R|B| {
|
||||
protected constructor(): R|B| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -1,9 +1,9 @@
|
||||
FILE: sealedClassConstructorCall.kt
|
||||
public sealed class A : R|kotlin/Any| {
|
||||
private constructor(): R|A| {
|
||||
protected constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final val b: R|A| = R|/A.A|()
|
||||
public final val b: R|A| = <HIDDEN: /A.A is invisible>#()
|
||||
public get(): R|A|
|
||||
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
sealed class A
|
||||
|
||||
val b = <!SEALED_CLASS_CONSTRUCTOR_CALL{LT}!><!SEALED_CLASS_CONSTRUCTOR_CALL{PSI}!>A<!>()<!>
|
||||
val b = <!HIDDEN{LT}!><!HIDDEN{PSI}!>A<!>()<!>
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
FILE: sealedSupertype.kt
|
||||
public sealed class A : R|kotlin/Any| {
|
||||
private constructor(): R|A| {
|
||||
protected constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ FILE: sealedSupertype.kt
|
||||
|
||||
}
|
||||
public sealed class P : R|kotlin/Any| {
|
||||
private constructor(): R|P| {
|
||||
protected constructor(): R|P| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: a.kt
|
||||
public sealed class Base : R|kotlin/Any| {
|
||||
private constructor(): R|Base| {
|
||||
protected constructor(): R|Base| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: exhaustiveness_sealedClass.kt
|
||||
public sealed class Base : R|kotlin/Any| {
|
||||
private constructor(): R|Base| {
|
||||
protected constructor(): R|Base| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: exhaustiveness_sealedObject.kt
|
||||
public sealed class A : R|kotlin/Any| {
|
||||
private constructor(): R|A| {
|
||||
protected constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,12 +1,12 @@
|
||||
FILE: exhaustiveness_sealedSubClass.kt
|
||||
public sealed class A : R|kotlin/Any| {
|
||||
private constructor(): R|A| {
|
||||
protected constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public sealed class B : R|A| {
|
||||
private constructor(): R|B| {
|
||||
protected constructor(): R|B| {
|
||||
super<R|A|>()
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ FILE: exhaustiveness_sealedSubClass.kt
|
||||
|
||||
}
|
||||
public sealed class D : R|B| {
|
||||
private constructor(): R|D| {
|
||||
protected constructor(): R|D| {
|
||||
super<R|B|>()
|
||||
}
|
||||
|
||||
}
|
||||
public sealed class E : R|B| {
|
||||
private constructor(): R|E| {
|
||||
protected constructor(): R|E| {
|
||||
super<R|B|>()
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -5,7 +5,7 @@ FILE: classifierAccessFromCompanion.kt
|
||||
}
|
||||
|
||||
public sealed class Function : R|kotlin/Any| {
|
||||
private constructor(): R|Factory.Function| {
|
||||
protected constructor(): R|Factory.Function| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -111,7 +111,7 @@ FILE: RedundantVisibilityModifierChecker.kt
|
||||
|
||||
}
|
||||
public sealed class G : R|kotlin/Any| {
|
||||
private constructor(y: R|kotlin/Int|): R|G| {
|
||||
protected constructor(y: R|kotlin/Int|): R|G| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: test.kt
|
||||
public sealed class Test : R|kotlin/Any| {
|
||||
private constructor(): R|test/Test| {
|
||||
protected constructor(): R|test/Test| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: recursiveCallOnWhenWithSealedClass.kt
|
||||
public sealed class Maybe<T> : R|kotlin/Any| {
|
||||
private constructor<T>(): R|Maybe<T>| {
|
||||
protected constructor<T>(): R|Maybe<T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FILE: sealedClass.kt
|
||||
public sealed class Foo : R|kotlin/Any| {
|
||||
private constructor(value: R|kotlin/String|): R|Foo| {
|
||||
protected constructor(value: R|kotlin/String|): R|Foo| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ FILE: kt37327.kt
|
||||
public abstract interface Q : R|kotlin/Any| {
|
||||
}
|
||||
public sealed class A : R|Q| {
|
||||
private constructor(): R|A| {
|
||||
protected constructor(): R|A| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: lambdaInWhenBranch.kt
|
||||
private sealed class Sealed : R|kotlin/Any| {
|
||||
private constructor(): R|Sealed| {
|
||||
protected constructor(): R|Sealed| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
FILE: bareWithSubjectTypeAlias.kt
|
||||
public sealed class A<out T> : R|kotlin/Any| {
|
||||
private constructor<out T>(): R|A<T>| {
|
||||
protected constructor<out T>(): R|A<T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ val DIAGNOSTICS_LIST = DiagnosticListBuilder.buildDiagnosticList {
|
||||
val CONSTRUCTOR_IN_OBJECT by error<FirSourceElement, KtDeclaration>(PositioningStrategy.DECLARATION_SIGNATURE)
|
||||
val CONSTRUCTOR_IN_INTERFACE by error<FirSourceElement, KtDeclaration>(PositioningStrategy.DECLARATION_SIGNATURE)
|
||||
val NON_PRIVATE_CONSTRUCTOR_IN_ENUM by error<FirSourceElement, PsiElement>()
|
||||
val NON_PRIVATE_CONSTRUCTOR_IN_SEALED by error<FirSourceElement, PsiElement>()
|
||||
val NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED by error<FirSourceElement, PsiElement>()
|
||||
val CYCLIC_CONSTRUCTOR_DELEGATION_CALL by warning<FirSourceElement, PsiElement>()
|
||||
val PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED by warning<FirSourceElement, PsiElement>(PositioningStrategy.SECONDARY_CONSTRUCTOR_DELEGATION_CALL)
|
||||
val SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR by warning<FirSourceElement, PsiElement>()
|
||||
|
||||
+1
-1
@@ -95,7 +95,7 @@ object FirErrors {
|
||||
val CONSTRUCTOR_IN_OBJECT by error0<FirSourceElement, KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE)
|
||||
val CONSTRUCTOR_IN_INTERFACE by error0<FirSourceElement, KtDeclaration>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE)
|
||||
val NON_PRIVATE_CONSTRUCTOR_IN_ENUM by error0<FirSourceElement, PsiElement>()
|
||||
val NON_PRIVATE_CONSTRUCTOR_IN_SEALED by error0<FirSourceElement, PsiElement>()
|
||||
val NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED by error0<FirSourceElement, PsiElement>()
|
||||
val CYCLIC_CONSTRUCTOR_DELEGATION_CALL by warning0<FirSourceElement, PsiElement>()
|
||||
val PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED by warning0<FirSourceElement, PsiElement>(SourceElementPositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL)
|
||||
val SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR by warning0<FirSourceElement, PsiElement>()
|
||||
|
||||
+10
-4
@@ -14,6 +14,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
object FirConstructorAllowedChecker : FirConstructorChecker() {
|
||||
override fun check(declaration: FirConstructor, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
@@ -30,10 +32,14 @@ object FirConstructorAllowedChecker : FirConstructorChecker() {
|
||||
ClassKind.ENUM_CLASS -> if (declaration.visibility != Visibilities.Private) {
|
||||
reporter.reportOn(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM, context)
|
||||
}
|
||||
ClassKind.CLASS -> if (containingClass is FirRegularClass && containingClass.modality == Modality.SEALED &&
|
||||
declaration.visibility != Visibilities.Private
|
||||
) {
|
||||
reporter.reportOn(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED, context)
|
||||
ClassKind.CLASS -> if (containingClass is FirRegularClass && containingClass.modality == Modality.SEALED) {
|
||||
val modifierList = with(FirModifierList) { source.getModifierList() } ?: return
|
||||
val hasIllegalModifier = modifierList.modifiers.any {
|
||||
it.token != KtTokens.PROTECTED_KEYWORD && it.token != KtTokens.PRIVATE_KEYWORD
|
||||
}
|
||||
if (hasIllegalModifier) {
|
||||
reporter.reportOn(source, FirErrors.NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED, context)
|
||||
}
|
||||
}
|
||||
ClassKind.ANNOTATION_CLASS -> {
|
||||
// DO NOTHING
|
||||
|
||||
+2
-2
@@ -101,7 +101,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NONE_APPLICABLE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_MEMBER_FUNCTION_NO_BODY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOTHING_TO_OVERRIDE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_AN_ANNOTATION_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_A_LOOP_LABEL
|
||||
@@ -247,7 +247,7 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
|
||||
map.put(CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects")
|
||||
map.put(CONSTRUCTOR_IN_INTERFACE, "An interface may not have a constructor")
|
||||
map.put(NON_PRIVATE_CONSTRUCTOR_IN_ENUM, "Constructor must be private in enum class")
|
||||
map.put(NON_PRIVATE_CONSTRUCTOR_IN_SEALED, "Constructor must be private in sealed class")
|
||||
map.put(NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED, "Constructor must be private or protected in sealed class")
|
||||
map.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain")
|
||||
map.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected")
|
||||
map.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor")
|
||||
|
||||
+3
-1
@@ -740,7 +740,9 @@ class DeclarationsConverter(
|
||||
extractArgumentsFrom(classWrapper.superTypeCallEntry, stubMode)
|
||||
}
|
||||
|
||||
val explicitVisibility = if (primaryConstructor != null) modifiers.getVisibility() else null
|
||||
val explicitVisibility = runIf(primaryConstructor != null) {
|
||||
modifiers.getVisibility().takeUnless { it == Visibilities.Unknown }
|
||||
}
|
||||
val status = FirDeclarationStatusImpl(explicitVisibility ?: defaultVisibility, Modality.FINAL).apply {
|
||||
isExpect = modifiers.hasExpect() || classWrapper.hasExpect()
|
||||
isActual = modifiers.hasActual()
|
||||
|
||||
+1
-1
@@ -64,7 +64,7 @@ class ClassWrapper(
|
||||
fun defaultConstructorVisibility(): Visibility {
|
||||
return when {
|
||||
isObject() || isEnum() || isEnumEntry() -> Visibilities.Private
|
||||
isSealed() -> Visibilities.Private
|
||||
isSealed() -> Visibilities.Protected
|
||||
else -> Visibilities.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
@@ -657,11 +657,11 @@ class RawFirBuilder(
|
||||
// See DescriptorUtils#getDefaultConstructorVisibility in core.descriptors
|
||||
fun defaultVisibility() = when {
|
||||
owner is KtObjectDeclaration || owner.hasModifier(ENUM_KEYWORD) || owner is KtEnumEntry -> Visibilities.Private
|
||||
owner.hasModifier(SEALED_KEYWORD) -> Visibilities.Private
|
||||
owner.hasModifier(SEALED_KEYWORD) -> Visibilities.Protected
|
||||
else -> Visibilities.Unknown
|
||||
}
|
||||
|
||||
val explicitVisibility = this?.visibility
|
||||
val explicitVisibility = this?.visibility?.takeUnless { it == Visibilities.Unknown }
|
||||
val status = FirDeclarationStatusImpl(explicitVisibility ?: defaultVisibility(), Modality.FINAL).apply {
|
||||
isExpect = this@toFirConstructor?.hasExpectModifier() == true || owner.hasExpectModifier()
|
||||
isActual = this@toFirConstructor?.hasActualModifier() == true
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ FILE: enums.kt
|
||||
|
||||
}
|
||||
public? final? enum class Planet : R|kotlin/Enum<Planet>| {
|
||||
public? constructor(m: Double, r: Double): R|Planet| {
|
||||
private constructor(m: Double, r: Double): R|Planet| {
|
||||
super<R|kotlin/Enum<Planet>|>()
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ FILE: enums.kt
|
||||
|
||||
}
|
||||
public? final? enum class PseudoInsn : R|kotlin/Enum<PseudoInsn>| {
|
||||
public? constructor(signature: String = String(()V)): R|PseudoInsn| {
|
||||
private constructor(signature: String = String(()V)): R|PseudoInsn| {
|
||||
super<R|kotlin/Enum<PseudoInsn>|>()
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ FILE: enums.kt
|
||||
|
||||
}
|
||||
public? final? enum class Planet : R|kotlin/Enum<Planet>| {
|
||||
public? constructor(m: Double, r: Double): R|Planet| {
|
||||
private constructor(m: Double, r: Double): R|Planet| {
|
||||
super<R|kotlin/Enum<Planet>|>()
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ FILE: enums.kt
|
||||
|
||||
}
|
||||
public? final? enum class PseudoInsn : R|kotlin/Enum<PseudoInsn>| {
|
||||
public? constructor(signature: String = String(()V)): R|PseudoInsn| {
|
||||
private constructor(signature: String = String(()V)): R|PseudoInsn| {
|
||||
super<R|kotlin/Enum<PseudoInsn>|>()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ FILE: enums2.kt
|
||||
|
||||
}
|
||||
public? final? enum class SomeEnum : R|kotlin/Enum<SomeEnum>| {
|
||||
public? constructor(x: Some): R|SomeEnum| {
|
||||
private constructor(x: Some): R|SomeEnum| {
|
||||
super<R|kotlin/Enum<SomeEnum>|>()
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ FILE: enums2.kt
|
||||
|
||||
}
|
||||
public? final? enum class SomeEnum : R|kotlin/Enum<SomeEnum>| {
|
||||
public? constructor(x: Some): R|SomeEnum| {
|
||||
private constructor(x: Some): R|SomeEnum| {
|
||||
super<R|kotlin/Enum<SomeEnum>|>()
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ final class TopLevelPrivate /* pkg.TopLevelPrivate*/ {
|
||||
}
|
||||
|
||||
public abstract class Season /* pkg.Season*/ {
|
||||
private Season();// .ctor()
|
||||
protected Season();// .ctor()
|
||||
|
||||
|
||||
class Nested ...
|
||||
@@ -53,8 +53,8 @@ public static final class Nested /* pkg.Season.Nested*/ extends pkg.Season {
|
||||
public abstract class SealedWithArgs /* pkg.SealedWithArgs*/ {
|
||||
private final int a;
|
||||
|
||||
private SealedWithArgs(int);// .ctor(int)
|
||||
protected SealedWithArgs(int);// .ctor(int)
|
||||
|
||||
public final int getA();// getA()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
sealed class Expr {
|
||||
private constructor() /* primary */ {
|
||||
protected constructor() /* primary */ {
|
||||
super/*Any*/()
|
||||
/* <init>() */
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
FILE fqName:<root> fileName:/sealedClasses.kt
|
||||
CLASS CLASS name:Expr modality:SEALED visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Expr
|
||||
CONSTRUCTOR visibility:private <> () returnType:<root>.Expr [primary]
|
||||
CONSTRUCTOR visibility:protected <> () returnType:<root>.Expr [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Expr modality:SEALED visibility:public superTypes:[kotlin.Any]'
|
||||
@@ -10,7 +10,7 @@ FILE fqName:<root> fileName:/sealedClasses.kt
|
||||
CONSTRUCTOR visibility:public <> (number:kotlin.Double) returnType:<root>.Expr.Const [primary]
|
||||
VALUE_PARAMETER name:number index:0 type:kotlin.Double
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.Expr'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'protected constructor <init> () [primary] declared in <root>.Expr'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Const modality:FINAL visibility:public superTypes:[<root>.Expr]'
|
||||
PROPERTY name:number visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:number type:kotlin.Double visibility:private [final]
|
||||
@@ -42,7 +42,7 @@ FILE fqName:<root> fileName:/sealedClasses.kt
|
||||
VALUE_PARAMETER name:e1 index:0 type:<root>.Expr
|
||||
VALUE_PARAMETER name:e2 index:1 type:<root>.Expr
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.Expr'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'protected constructor <init> () [primary] declared in <root>.Expr'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Sum modality:FINAL visibility:public superTypes:[<root>.Expr]'
|
||||
PROPERTY name:e1 visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:e1 type:<root>.Expr visibility:private [final]
|
||||
@@ -83,7 +83,7 @@ FILE fqName:<root> fileName:/sealedClasses.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Expr.NotANumber
|
||||
CONSTRUCTOR visibility:private <> () returnType:<root>.Expr.NotANumber [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.Expr'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'protected constructor <init> () [primary] declared in <root>.Expr'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:NotANumber modality:FINAL visibility:public superTypes:[<root>.Expr]'
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
expect sealed class Ops {
|
||||
private expect constructor() /* primary */
|
||||
protected expect constructor() /* primary */
|
||||
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ expect class Add : Ops {
|
||||
}
|
||||
|
||||
sealed class Ops {
|
||||
private constructor() /* primary */ {
|
||||
protected constructor() /* primary */ {
|
||||
super/*Any*/()
|
||||
/* <init>() */
|
||||
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
FILE fqName:<root> fileName:/expectedSealedClass.kt
|
||||
CLASS CLASS name:Ops modality:SEALED visibility:public [expect] superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Ops
|
||||
CONSTRUCTOR visibility:private <> () returnType:<root>.Ops [primary,expect]
|
||||
CONSTRUCTOR visibility:protected <> () returnType:<root>.Ops [primary,expect]
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [expect,fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any
|
||||
@@ -33,7 +33,7 @@ FILE fqName:<root> fileName:/expectedSealedClass.kt
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS CLASS name:Ops modality:SEALED visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Ops
|
||||
CONSTRUCTOR visibility:private <> () returnType:<root>.Ops [primary]
|
||||
CONSTRUCTOR visibility:protected <> () returnType:<root>.Ops [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Ops modality:SEALED visibility:public superTypes:[kotlin.Any]'
|
||||
@@ -54,7 +54,7 @@ FILE fqName:<root> fileName:/expectedSealedClass.kt
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Add
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Add [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'private constructor <init> () [primary] declared in <root>.Ops'
|
||||
DELEGATING_CONSTRUCTOR_CALL 'protected constructor <init> () [primary] declared in <root>.Ops'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Add modality:FINAL visibility:public superTypes:[<root>.Ops]'
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
|
||||
+2
-2
@@ -260,8 +260,8 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED) { firDiagnostic ->
|
||||
NonPrivateConstructorInSealedImpl(
|
||||
add(FirErrors.NON_PRIVATE_OR_PROTECTED_CONSTRUCTOR_IN_SEALED) { firDiagnostic ->
|
||||
NonPrivateOrProtectedConstructorInSealedImpl(
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
token,
|
||||
)
|
||||
|
||||
+2
-2
@@ -190,8 +190,8 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
override val diagnosticClass get() = NonPrivateConstructorInEnum::class
|
||||
}
|
||||
|
||||
abstract class NonPrivateConstructorInSealed : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = NonPrivateConstructorInSealed::class
|
||||
abstract class NonPrivateOrProtectedConstructorInSealed : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = NonPrivateOrProtectedConstructorInSealed::class
|
||||
}
|
||||
|
||||
abstract class CyclicConstructorDelegationCall : KtFirDiagnostic<PsiElement>() {
|
||||
|
||||
+2
-2
@@ -299,10 +299,10 @@ internal class NonPrivateConstructorInEnumImpl(
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
internal class NonPrivateConstructorInSealedImpl(
|
||||
internal class NonPrivateOrProtectedConstructorInSealedImpl(
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.NonPrivateConstructorInSealed(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
) : KtFirDiagnostic.NonPrivateOrProtectedConstructorInSealed(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
override val firDiagnostic: FirPsiDiagnostic<*> by weakRef(firDiagnostic)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user