From d70d2ca146416595ff90cd01ef2ec0c4c00e0219 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 20 Feb 2015 15:05:15 +0300 Subject: [PATCH] Nullability of error types is not known #KT-6829 Fixed --- .../load/kotlin/KotlinJvmCheckerProvider.kt | 4 +-- .../nullabilityWarnings/kt6829.kt | 27 +++++++++++++++++++ .../nullabilityWarnings/kt6829.txt | 4 +++ .../checkers/JetDiagnosticsTestGenerated.java | 6 +++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.kt create mode 100644 compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.txt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt index 65b0ceb99a7..5cb93368679 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/KotlinJvmCheckerProvider.kt @@ -152,13 +152,13 @@ private fun checkTypeParameterDescriptorsAreNotReified( public class JavaNullabilityWarningsChecker : AdditionalTypeChecker { private fun JetType.mayBeNull(): NullabilityInformationSource? { - if (!isFlexible() && TypeUtils.isNullableType(this)) return NullabilityInformationSource.KOTLIN + if (!isError() && !isFlexible() && TypeUtils.isNullableType(this)) return NullabilityInformationSource.KOTLIN if (getAnnotations().isMarkedNullable()) return NullabilityInformationSource.JAVA return null } private fun JetType.mustNotBeNull(): NullabilityInformationSource? { - if (!isFlexible() && !TypeUtils.isNullableType(this)) return NullabilityInformationSource.KOTLIN + if (!isError() && !isFlexible() && !TypeUtils.isNullableType(this)) return NullabilityInformationSource.KOTLIN if (!isMarkedNullable() && getAnnotations().isMarkedNotNull()) return NullabilityInformationSource.JAVA return null } diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.kt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.kt new file mode 100644 index 00000000000..21129c3c083 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.kt @@ -0,0 +1,27 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +// KT-6829 False warning on map to @Nullable + +// FILE: p/J.java +package p; + +import org.jetbrains.annotations.*; + +public class J { + + @Nullable + public String method() { return ""; } +} + +// FILE: k.kt + +import p.* + +fun foo(collection: Collection) { + val mapped = collection.map { it.method() } + mapped[0].length() +} + +public fun Iterable.map(transform: (T) -> R): List { + null!! +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.txt b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.txt new file mode 100644 index 00000000000..066df5f85b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.txt @@ -0,0 +1,4 @@ +package + +internal fun foo(/*0*/ collection: kotlin.Collection): kotlin.Unit +public fun kotlin.Iterable.map(/*0*/ transform: (T) -> R): kotlin.List diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index ad1591b8a61..44beab74567 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -8923,6 +8923,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt6829.kt") + public void testKt6829() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/kt6829.kt"); + doTest(fileName); + } + @TestMetadata("multiDeclaration.kt") public void testMultiDeclaration() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/platformTypes/nullabilityWarnings/multiDeclaration.kt");