Improve diagnostics for lateinit properties with generic type

#KT-11834 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-09-05 14:32:20 +03:00
parent 356f903645
commit 081b732070
3 changed files with 13 additions and 1 deletions
@@ -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"))
@@ -0,0 +1,3 @@
class C<V>() {
<error descr="[INAPPLICABLE_LATEINIT_MODIFIER] 'lateinit' modifier is not allowed on properties of a type with nullable upper bound">lateinit</error> var item: V
}
@@ -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");