diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LateinitModifierApplicabilityChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LateinitModifierApplicabilityChecker.kt index 5c1d0da97fa..04164a4174a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LateinitModifierApplicabilityChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LateinitModifierApplicabilityChecker.kt @@ -45,9 +45,12 @@ object LateinitModifierApplicabilityChecker { trace.report(Errors.INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is allowed only on mutable $variables")) } - if (TypeUtils.isNullableType(type)) { + if (type.isMarkedNullable) { trace.report(Errors.INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on $variables of nullable types")) } + else if (TypeUtils.isNullableType(type)) { + trace.report(Errors.INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on $variables of a type with nullable upper bound")) + } if (KotlinBuiltIns.isPrimitiveType(type)) { trace.report(Errors.INAPPLICABLE_LATEINIT_MODIFIER.on(modifier, "is not allowed on $variables of primitive types")) diff --git a/idea/testData/checker/diagnosticsMessage/lateinitOfATypeWithNullableUpperBound.kt b/idea/testData/checker/diagnosticsMessage/lateinitOfATypeWithNullableUpperBound.kt new file mode 100644 index 00000000000..fed09f7e74c --- /dev/null +++ b/idea/testData/checker/diagnosticsMessage/lateinitOfATypeWithNullableUpperBound.kt @@ -0,0 +1,3 @@ +class C() { + lateinit var item: V +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java index 9e1920fc264..53da4bb1095 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/PsiCheckerTestGenerated.java @@ -1004,6 +1004,12 @@ public class PsiCheckerTestGenerated extends AbstractPsiCheckerTest { doTest(fileName); } + @TestMetadata("lateinitOfATypeWithNullableUpperBound.kt") + public void testLateinitOfATypeWithNullableUpperBound() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/diagnosticsMessage/lateinitOfATypeWithNullableUpperBound.kt"); + doTest(fileName); + } + @TestMetadata("nArgumentsExpectedMessage.kt") public void testNArgumentsExpectedMessage() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/checker/diagnosticsMessage/nArgumentsExpectedMessage.kt");