MUST_BE_INITIALIZED: take into account containingDeclaration's modality
^KT-58587 Fixed Review: https://jetbrains.team/p/kt/reviews/10136 This commit is important in scope of KT-57553. It makes the migration more smooth. Other related tests: - testUninitializedOrReassignedVariables - testAugmentedAssignmentInInitializer
This commit is contained in:
+12
@@ -2948,6 +2948,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOff.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOff() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOff.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOn.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOn() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOn.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("SetterWithExplicitType.kt")
|
@TestMetadata("SetterWithExplicitType.kt")
|
||||||
public void testSetterWithExplicitType() throws Exception {
|
public void testSetterWithExplicitType() throws Exception {
|
||||||
|
|||||||
+12
@@ -2948,6 +2948,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
|||||||
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOff.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOff() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOff.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOn.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOn() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOn.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("SetterWithExplicitType.kt")
|
@TestMetadata("SetterWithExplicitType.kt")
|
||||||
public void testSetterWithExplicitType() throws Exception {
|
public void testSetterWithExplicitType() throws Exception {
|
||||||
|
|||||||
+12
@@ -2948,6 +2948,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
|||||||
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOff.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOff() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOff.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOn.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOn() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOn.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("SetterWithExplicitType.kt")
|
@TestMetadata("SetterWithExplicitType.kt")
|
||||||
public void testSetterWithExplicitType() throws Exception {
|
public void testSetterWithExplicitType() throws Exception {
|
||||||
|
|||||||
+12
@@ -2954,6 +2954,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
|||||||
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOff.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOff() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOff.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOn.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOn() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOn.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("SetterWithExplicitType.kt")
|
@TestMetadata("SetterWithExplicitType.kt")
|
||||||
public void testSetterWithExplicitType() throws Exception {
|
public void testSetterWithExplicitType() throws Exception {
|
||||||
|
|||||||
@@ -372,18 +372,29 @@ class IrBuiltInsOverFir(
|
|||||||
override val ieee754equalsFunByOperandType: MutableMap<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
override val ieee754equalsFunByOperandType: MutableMap<IrClassifierSymbol, IrSimpleFunctionSymbol>
|
||||||
get() = _ieee754equalsFunByOperandType
|
get() = _ieee754equalsFunByOperandType
|
||||||
|
|
||||||
override lateinit var eqeqeqSymbol: IrSimpleFunctionSymbol private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var eqeqSymbol: IrSimpleFunctionSymbol private set
|
final override var eqeqeqSymbol: IrSimpleFunctionSymbol private set
|
||||||
override lateinit var throwCceSymbol: IrSimpleFunctionSymbol private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var throwIseSymbol: IrSimpleFunctionSymbol private set
|
final override var eqeqSymbol: IrSimpleFunctionSymbol private set
|
||||||
override lateinit var andandSymbol: IrSimpleFunctionSymbol private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var ororSymbol: IrSimpleFunctionSymbol private set
|
final override var throwCceSymbol: IrSimpleFunctionSymbol private set
|
||||||
override lateinit var noWhenBranchMatchedExceptionSymbol: IrSimpleFunctionSymbol private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var illegalArgumentExceptionSymbol: IrSimpleFunctionSymbol private set
|
final override var throwIseSymbol: IrSimpleFunctionSymbol private set
|
||||||
override lateinit var dataClassArrayMemberHashCodeSymbol: IrSimpleFunctionSymbol private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var dataClassArrayMemberToStringSymbol: IrSimpleFunctionSymbol private set
|
final override var andandSymbol: IrSimpleFunctionSymbol private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var ororSymbol: IrSimpleFunctionSymbol private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var noWhenBranchMatchedExceptionSymbol: IrSimpleFunctionSymbol private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var illegalArgumentExceptionSymbol: IrSimpleFunctionSymbol private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var dataClassArrayMemberHashCodeSymbol: IrSimpleFunctionSymbol private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var dataClassArrayMemberToStringSymbol: IrSimpleFunctionSymbol private set
|
||||||
|
|
||||||
override lateinit var checkNotNullSymbol: IrSimpleFunctionSymbol private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var checkNotNullSymbol: IrSimpleFunctionSymbol private set
|
||||||
override val arrayOfNulls: IrSimpleFunctionSymbol by lazy {
|
override val arrayOfNulls: IrSimpleFunctionSymbol by lazy {
|
||||||
findFunctions(kotlinPackage, Name.identifier("arrayOfNulls")).first {
|
findFunctions(kotlinPackage, Name.identifier("arrayOfNulls")).first {
|
||||||
it.owner.dispatchReceiverParameter == null && it.owner.valueParameters.size == 1 &&
|
it.owner.dispatchReceiverParameter == null && it.owner.valueParameters.size == 1 &&
|
||||||
@@ -394,10 +405,14 @@ class IrBuiltInsOverFir(
|
|||||||
override val linkageErrorSymbol: IrSimpleFunctionSymbol
|
override val linkageErrorSymbol: IrSimpleFunctionSymbol
|
||||||
get() = TODO("Not yet implemented")
|
get() = TODO("Not yet implemented")
|
||||||
|
|
||||||
override lateinit var lessFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var lessOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
final override var lessFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||||
override lateinit var greaterOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
override lateinit var greaterFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
final override var lessOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var greaterOrEqualFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||||
|
@Suppress("RedundantModalityModifier") // Explicit `final` keyword can be dropped after bootstrap update
|
||||||
|
final override var greaterFunByOperandType: Map<IrClassifierSymbol, IrSimpleFunctionSymbol> private set
|
||||||
|
|
||||||
init {
|
init {
|
||||||
with(this.operatorsPackageFragment) {
|
with(this.operatorsPackageFragment) {
|
||||||
|
|||||||
+8
-1
@@ -628,7 +628,7 @@ class ControlFlowInformationProviderImpl private constructor(
|
|||||||
val property = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor) as? KtProperty
|
val property = DescriptorToSourceUtils.descriptorToDeclaration(variableDescriptor) as? KtProperty
|
||||||
?: throw AssertionError("$variableDescriptor is not related to KtProperty")
|
?: throw AssertionError("$variableDescriptor is not related to KtProperty")
|
||||||
val setter = property.setter
|
val setter = property.setter
|
||||||
if (variableDescriptor.modality == Modality.FINAL && (setter == null || !setter.hasBody())) {
|
if (variableDescriptor.getEffectiveModality(languageVersionSettings) == Modality.FINAL && (setter == null || !setter.hasBody())) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1472,3 +1472,10 @@ class ControlFlowInformationProviderImpl private constructor(
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun PropertyDescriptor.getEffectiveModality(languageVersionSettings: LanguageVersionSettings): Modality =
|
||||||
|
when (languageVersionSettings.supportsFeature(LanguageFeature.TakeIntoAccountEffectivelyFinalInMustBeInitializedCheck) &&
|
||||||
|
modality == Modality.OPEN && (containingDeclaration as? ClassDescriptor)?.modality == Modality.FINAL) {
|
||||||
|
true -> Modality.FINAL
|
||||||
|
false -> modality
|
||||||
|
}
|
||||||
|
|||||||
Vendored
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// !LANGUAGE:-TakeIntoAccountEffectivelyFinalInMustBeInitializedCheck
|
||||||
|
open class Base {
|
||||||
|
open var x: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo : Base() {
|
||||||
|
override var x: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
x = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
// !LANGUAGE:-TakeIntoAccountEffectivelyFinalInMustBeInitializedCheck
|
||||||
|
open class Base {
|
||||||
|
open var x: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo : Base() {
|
||||||
|
<!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>override var x: String<!>
|
||||||
|
|
||||||
|
init {
|
||||||
|
x = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !LANGUAGE:+TakeIntoAccountEffectivelyFinalInMustBeInitializedCheck
|
||||||
|
open class Base {
|
||||||
|
open var x: String = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
class Foo : Base() {
|
||||||
|
override var x: String
|
||||||
|
|
||||||
|
init {
|
||||||
|
x = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+12
@@ -2954,6 +2954,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
runTest("compiler/testData/diagnostics/tests/backingField/LocalDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOff.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOff() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOff.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("MustBeInitializedEffectivelyFinalOn.kt")
|
||||||
|
public void testMustBeInitializedEffectivelyFinalOn() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/backingField/MustBeInitializedEffectivelyFinalOn.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("SetterWithExplicitType.kt")
|
@TestMetadata("SetterWithExplicitType.kt")
|
||||||
public void testSetterWithExplicitType() throws Exception {
|
public void testSetterWithExplicitType() throws Exception {
|
||||||
|
|||||||
@@ -275,6 +275,7 @@ enum class LanguageFeature(
|
|||||||
RefineTypeCheckingOnAssignmentsToJavaFields(KOTLIN_1_9, kind = BUG_FIX), // KT-46727
|
RefineTypeCheckingOnAssignmentsToJavaFields(KOTLIN_1_9, kind = BUG_FIX), // KT-46727
|
||||||
ValueClassesSecondaryConstructorWithBody(sinceVersion = KOTLIN_1_9, kind = UNSTABLE_FEATURE), // KT-55333
|
ValueClassesSecondaryConstructorWithBody(sinceVersion = KOTLIN_1_9, kind = UNSTABLE_FEATURE), // KT-55333
|
||||||
NativeJsProhibitLateinitIsInitializedIntrinsicWithoutPrivateAccess(KOTLIN_1_9, kind = BUG_FIX), // KT-27002
|
NativeJsProhibitLateinitIsInitializedIntrinsicWithoutPrivateAccess(KOTLIN_1_9, kind = BUG_FIX), // KT-27002
|
||||||
|
TakeIntoAccountEffectivelyFinalInMustBeInitializedCheck(KOTLIN_1_9, kind = OTHER), // KT-58587
|
||||||
|
|
||||||
// End of 1.* language features --------------------------------------------------
|
// End of 1.* language features --------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user