diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 67361207b18..3f89d7d7b1b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -563,6 +563,7 @@ public interface Errors { DiagnosticFactory0 EXPECTED_ENUM_ENTRY_WITH_BODY = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 EXPECTED_PROPERTY_INITIALIZER = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 EXPECTED_DELEGATED_PROPERTY = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 EXPECTED_LATEINIT_PROPERTY = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 ACTUAL_TYPE_ALIAS_NOT_TO_CLASS = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE); DiagnosticFactory0 diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 4afd0ab6bf6..4f84410e90c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -271,6 +271,7 @@ public class DefaultErrorMessages { MAP.put(EXPECTED_ENUM_ENTRY_WITH_BODY, "Expected enum entry cannot have a body"); MAP.put(EXPECTED_PROPERTY_INITIALIZER, "Expected property cannot have an initializer"); MAP.put(EXPECTED_DELEGATED_PROPERTY, "Expected property cannot be delegated"); + MAP.put(EXPECTED_LATEINIT_PROPERTY, "Expected property cannot be lateinit"); MAP.put(ACTUAL_TYPE_ALIAS_NOT_TO_CLASS, "Right-hand side of actual type alias should be a class, not another type alias"); MAP.put(ACTUAL_TYPE_ALIAS_TO_CLASS_WITH_DECLARATION_SITE_VARIANCE, "Aliased class should not have type parameters with declaration-site variance"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt index 5161b8d0eb9..a4319ae886b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/DeclarationsChecker.kt @@ -670,9 +670,14 @@ class DeclarationsChecker( else if (noExplicitTypeOrGetterType(property)) { trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property)) } - if (backingFieldRequired && !inInterface && propertyDescriptor.isLateInit && !isUninitialized && - trace[MUST_BE_LATEINIT, propertyDescriptor] != true) { - trace.report(UNNECESSARY_LATEINIT.on(property)) + + if (propertyDescriptor.isLateInit) { + if (propertyDescriptor.isExpect) { + trace.report(EXPECTED_LATEINIT_PROPERTY.on(property.modifierList?.getModifier(KtTokens.LATEINIT_KEYWORD) ?: property)) + } + if (backingFieldRequired && !inInterface && !isUninitialized && trace[MUST_BE_LATEINIT, propertyDescriptor] != true) { + trace.report(UNNECESSARY_LATEINIT.on(property)) + } } } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt index f5c0e0e1d90..da56c794b89 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/ModifiersChecker.kt @@ -191,9 +191,6 @@ object ModifierCheckerCore { // (see the KEEP https://github.com/Kotlin/KEEP/blob/master/proposals/sealed-class-inheritance.md) result += incompatibilityRegister(SEALED_KEYWORD, INNER_KEYWORD) - // lateinit is incompatible with header / expect - result += incompatibilityRegister(LATEINIT_KEYWORD, HEADER_KEYWORD, EXPECT_KEYWORD) - // header / expect / impl / actual are all incompatible result += incompatibilityRegister(HEADER_KEYWORD, EXPECT_KEYWORD, IMPL_KEYWORD, ACTUAL_KEYWORD) diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.kt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.kt index 9bfba462621..74f469447a6 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.kt @@ -23,6 +23,8 @@ expect class Foo { get() = "no" set(value) {} + lateinit var lateinitVar: String + val delegated: String by Delegate } diff --git a/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.txt b/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.txt index 2f8b94e29a1..e0c37021e86 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.txt +++ b/compiler/testData/diagnostics/tests/multiplatform/headerClass/memberPropertyKinds.txt @@ -17,6 +17,7 @@ public final expect class Foo { public expect final val delegated: kotlin.String public expect final val justVal: kotlin.String public expect final var justVar: kotlin.String + public expect final lateinit var lateinitVar: kotlin.String public expect final val valWithGet: kotlin.String public expect final var varWithGetSet: kotlin.String public expect final val kotlin.String.extensionVal: kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt index cf201cc8da5..e73e201c4b4 100644 --- a/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt +++ b/compiler/testData/diagnostics/tests/multiplatform/topLevelProperty/differentKindsOfProperties.kt @@ -1,4 +1,4 @@ -// !LANGUAGE: +MultiPlatformProjects +// !LANGUAGE: +MultiPlatformProjects +LateinitTopLevelProperties // MODULE: m1-common // FILE: common.kt @@ -28,7 +28,7 @@ expect var customAccessorVar: String expect const val constVal: Int -expect lateinit var lateinitVar: String +expect lateinit var lateinitVar: String expect val delegated: String by Delegate object Delegate { operator fun getValue(x: Any?, y: Any?): String = "" }