From 89d99e3989ed244707a31465586833c409a85ead Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 13 Jul 2018 17:51:11 +0300 Subject: [PATCH] Refine diagnostics for nullability migration warnings #KT-24911 Fixed --- .../jvm/checkers/JavaNullabilityChecker.kt | 57 +++++++++++-------- .../diagnostics/DefaultErrorMessagesJvm.java | 6 +- .../resolve/jvm/diagnostics/ErrorsJvm.java | 23 ++------ .../testData/cli/jvm/jsr305/Annotated.java | 7 ++- .../testData/cli/jvm/jsr305/MyNullable.java | 15 +++++ .../testData/cli/jvm/jsr305DeprecatedWarn.out | 2 +- compiler/testData/cli/jvm/jsr305Migration.kt | 3 +- .../cli/jvm/jsr305MigrationFqNameIgnore.out | 5 +- .../cli/jvm/jsr305MigrationIgnore.out | 5 +- .../testData/cli/jvm/jsr305MigrationWarn.out | 7 ++- compiler/testData/cli/jvm/jsr305NoFlag.out | 2 +- compiler/testData/cli/jvm/jsr305Warn.out | 2 +- .../tests/androidRecently.kt | 11 ++-- .../fromPlatformTypes/arithmetic.kt | 14 ++--- .../fromPlatformTypes/array.kt | 4 +- .../fromPlatformTypes/conditions.kt | 4 +- .../fromPlatformTypes/delegatedProperties.kt | 4 +- .../fromPlatformTypes/derefenceExtension.kt | 2 +- .../fromPlatformTypes/derefenceMember.kt | 2 +- .../fromPlatformTypes/for.kt | 3 +- .../fromPlatformTypes/invoke.kt | 4 +- .../fromPlatformTypes/kt6829.kt | 4 +- .../fromPlatformTypes/multiDeclaration.kt | 4 +- .../fromPlatformTypes/primitiveArray.kt | 5 +- .../nullabilityNicknames.kt | 10 ++-- .../typeQualifierDefault/fieldsAreNullable.kt | 2 +- .../overridingDefaultQualifier.kt | 14 ++--- .../typeQualifierDefault/springNullable.kt | 4 +- .../springNullablePackage.kt | 2 +- .../migration/migrationError.kt | 6 +- .../migration/migrationIgnore.kt | 6 +- .../migration/overrideConflicts.kt | 4 +- .../migration/stateRefinement.kt | 6 +- .../idea/highlighter/IdeErrorMessages.java | 4 ++ 34 files changed, 140 insertions(+), 113 deletions(-) create mode 100644 compiler/testData/cli/jvm/jsr305/MyNullable.java diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt index 09b251793bc..729e5a45313 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JavaNullabilityChecker.kt @@ -45,8 +45,8 @@ class JavaNullabilityChecker : AdditionalTypeChecker { c.expectedType, { c.dataFlowValueFactory.createDataFlowValue(expression, expressionType, c) } , c.dataFlowInfo - ) { expectedMustNotBeNull, actualMayBeNull -> - c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(expression, expectedMustNotBeNull, actualMayBeNull)) + ) { expectedType, actualType -> + c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(expression, expectedType, actualType)) } when (expression) { @@ -121,12 +121,15 @@ class JavaNullabilityChecker : AdditionalTypeChecker { receiverParameter.type, { dataFlowValue }, c.dataFlowInfo - ) { expectedMustNotBeNull, - actualMayBeNull -> - val reportOn = (receiverArgument as? ExpressionReceiver)?.expression ?: (c.call.calleeExpression ?: c.call.callElement) - c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on( - reportOn, expectedMustNotBeNull, actualMayBeNull - )) + ) { expectedType, + actualType -> + val receiverExpression = (receiverArgument as? ExpressionReceiver)?.expression + if (receiverExpression != null) { + c.trace.report(ErrorsJvm.RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(receiverExpression, actualType)) + } else { + val reportOn = c.call.calleeExpression ?: c.call.callElement + c.trace.report(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS.on(reportOn, expectedType, actualType)) + } } } @@ -135,22 +138,21 @@ class JavaNullabilityChecker : AdditionalTypeChecker { expectedType: KotlinType, dataFlowValue: () -> DataFlowValue, dataFlowInfo: DataFlowInfo, - reportWarning: (expectedMustNotBeNull: ErrorsJvm.NullabilityInformationSource, actualMayBeNull: ErrorsJvm.NullabilityInformationSource) -> Unit + reportWarning: (expectedType: KotlinType, actualType: KotlinType) -> Unit ) { if (TypeUtils.noExpectedType(expectedType)) { return } - val expectedMustNotBeNull = expectedType.mustNotBeNull() - val actualMayBeNull = expressionType.mayBeNull() - if (expectedMustNotBeNull == ErrorsJvm.NullabilityInformationSource.KOTLIN && actualMayBeNull == ErrorsJvm.NullabilityInformationSource.KOTLIN) { + val expectedMustNotBeNull = expectedType.mustNotBeNull() ?: return + val actualMayBeNull = expressionType.mayBeNull() ?: return + if (expectedMustNotBeNull.isFromKotlin && actualMayBeNull.isFromKotlin) { // a type mismatch error will be reported elsewhere return } - if (expectedMustNotBeNull != null && actualMayBeNull != null && - dataFlowInfo.getStableNullability(dataFlowValue()) != Nullability.NOT_NULL) { - reportWarning(expectedMustNotBeNull, actualMayBeNull) + if (dataFlowInfo.getStableNullability(dataFlowValue()) != Nullability.NOT_NULL) { + reportWarning(expectedMustNotBeNull.enhancedType, actualMayBeNull.enhancedType) } } @@ -159,23 +161,30 @@ class JavaNullabilityChecker : AdditionalTypeChecker { dataFlowValue: () -> DataFlowValue, c: ResolutionContext<*>, body: () -> T - ) = if (type.mustNotBeNull() == ErrorsJvm.NullabilityInformationSource.JAVA && + ) = if (type.mustNotBeNull()?.isFromJava == true && c.dataFlowInfo.getStableNullability(dataFlowValue()).canBeNull()) body() else null - private fun KotlinType.mustNotBeNull(): ErrorsJvm.NullabilityInformationSource? = when { - !isError && !isFlexible() && !TypeUtils.acceptsNullable(this) -> ErrorsJvm.NullabilityInformationSource.KOTLIN - isFlexible() && !TypeUtils.acceptsNullable(asFlexibleType().upperBound) -> ErrorsJvm.NullabilityInformationSource.KOTLIN - this is TypeWithEnhancement && enhancement.mustNotBeNull() != null -> ErrorsJvm.NullabilityInformationSource.JAVA + private class EnhancedNullabilityInfo(val enhancedType: KotlinType, val isFromJava: Boolean) { + val isFromKotlin get() = !isFromJava + } + + private fun KotlinType.enhancementFromKotlin() = EnhancedNullabilityInfo(this, isFromJava = false) + private fun TypeWithEnhancement.enhancementFromJava() = EnhancedNullabilityInfo(enhancement, isFromJava = true) + + private fun KotlinType.mustNotBeNull(): EnhancedNullabilityInfo? = when { + !isError && !isFlexible() && !TypeUtils.acceptsNullable(this) -> enhancementFromKotlin() + isFlexible() && !TypeUtils.acceptsNullable(asFlexibleType().upperBound) -> enhancementFromKotlin() + this is TypeWithEnhancement && enhancement.mustNotBeNull() != null -> enhancementFromJava() else -> null } - private fun KotlinType.mayBeNull(): ErrorsJvm.NullabilityInformationSource? = when { - !isError && !isFlexible() && TypeUtils.acceptsNullable(this) -> ErrorsJvm.NullabilityInformationSource.KOTLIN - isFlexible() && TypeUtils.acceptsNullable(asFlexibleType().lowerBound) -> ErrorsJvm.NullabilityInformationSource.KOTLIN - this is TypeWithEnhancement && enhancement.mayBeNull() != null -> ErrorsJvm.NullabilityInformationSource.JAVA + private fun KotlinType.mayBeNull(): EnhancedNullabilityInfo? = when { + !isError && !isFlexible() && TypeUtils.acceptsNullable(this) -> enhancementFromKotlin() + isFlexible() && TypeUtils.acceptsNullable(asFlexibleType().lowerBound) -> enhancementFromKotlin() + this is TypeWithEnhancement && enhancement.mayBeNull() != null -> enhancementFromJava() else -> null } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java index ec1167a4557..dfc000daf1c 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/DefaultErrorMessagesJvm.java @@ -87,8 +87,10 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension { MAP.put(INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER, "Interfaces can call default methods via super only within @JvmDefault members. Please annotate the containing interface member with @JvmDefault"); MAP.put(SUBCLASS_CANT_CALL_COMPANION_PROTECTED_NON_STATIC, "Using non-JVM static members protected in the superclass companion is unsupported yet"); - MAP.put(ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, - "Expected type does not accept nulls in {0}, but the value may be null in {1}", Renderers.TO_STRING, Renderers.TO_STRING); + MAP.put(NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE); + MAP.put(RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, + "Unsafe use of a nullable receiver of type {0}", RENDER_TYPE); + MAP.put(WHEN_ENUM_CAN_BE_NULL_IN_JAVA, "Enum argument can be null in Java, but exhaustive when contains no null branch"); MAP.put(JAVA_CLASS_ON_COMPANION, diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java index 3d742611ea6..71dddd62d66 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/diagnostics/ErrorsJvm.java @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.resolve.jvm.diagnostics; import com.intellij.psi.PsiElement; -import org.jetbrains.annotations.NotNull; import org.jetbrains.kotlin.descriptors.DeclarationDescriptor; import org.jetbrains.kotlin.diagnostics.*; import org.jetbrains.kotlin.name.FqName; @@ -125,26 +124,12 @@ public interface ErrorsJvm { DiagnosticFactory0 EXPLICIT_METADATA_IS_DISALLOWED = DiagnosticFactory0.create(ERROR); - enum NullabilityInformationSource { - KOTLIN { - @NotNull - @Override - public String toString() { - return "Kotlin"; - } - }, - JAVA { - @NotNull - @Override - public String toString() { - return "Java"; - } - } - } - - DiagnosticFactory2 NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS + DiagnosticFactory2 NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS = DiagnosticFactory2.create(WARNING); + DiagnosticFactory1 RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS + = DiagnosticFactory1.create(WARNING); + @SuppressWarnings("UnusedDeclaration") Object _initializer = new Object() { { diff --git a/compiler/testData/cli/jvm/jsr305/Annotated.java b/compiler/testData/cli/jvm/jsr305/Annotated.java index 4e63f6ca5bb..45afb3c043a 100644 --- a/compiler/testData/cli/jvm/jsr305/Annotated.java +++ b/compiler/testData/cli/jvm/jsr305/Annotated.java @@ -5,4 +5,9 @@ public class Annotated { public void bar(@MyMigrationNonnull String x) { } -} \ No newline at end of file + + @MyNullable + public String nullable() { + return null; + } +} diff --git a/compiler/testData/cli/jvm/jsr305/MyNullable.java b/compiler/testData/cli/jvm/jsr305/MyNullable.java new file mode 100644 index 00000000000..47be3bf8f57 --- /dev/null +++ b/compiler/testData/cli/jvm/jsr305/MyNullable.java @@ -0,0 +1,15 @@ +import javax.annotation.*; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +import javax.annotation.meta.TypeQualifierNickname; +import javax.annotation.meta.When; + +@Documented +@TypeQualifierNickname +@Nonnull(when = When.MAYBE) +@Retention(RetentionPolicy.RUNTIME) +public @interface MyNullable { + +} diff --git a/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out b/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out index d0956f6dc72..4f93b4809e5 100644 --- a/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out +++ b/compiler/testData/cli/jvm/jsr305DeprecatedWarn.out @@ -1,5 +1,5 @@ warning: argument -Xjsr305-annotations is deprecated. Please use -Xjsr305 instead -compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected a.foo(null) ^ OK diff --git a/compiler/testData/cli/jvm/jsr305Migration.kt b/compiler/testData/cli/jvm/jsr305Migration.kt index 0fbd0819b25..bc8c4671d3e 100644 --- a/compiler/testData/cli/jvm/jsr305Migration.kt +++ b/compiler/testData/cli/jvm/jsr305Migration.kt @@ -1,4 +1,5 @@ fun test(annotated: Annotated) { annotated.foo(null) annotated.bar(null) -} \ No newline at end of file + annotated.nullable().length +} diff --git a/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out b/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out index 6a6ee78e833..ca098ea8832 100644 --- a/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out +++ b/compiler/testData/cli/jvm/jsr305MigrationFqNameIgnore.out @@ -1,4 +1,7 @@ -compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: type mismatch: inferred type is Nothing? but String was expected annotated.foo(null) ^ +compiler/testData/cli/jvm/jsr305Migration.kt:4:5: warning: unsafe use of a nullable receiver of type String? + annotated.nullable().length + ^ OK diff --git a/compiler/testData/cli/jvm/jsr305MigrationIgnore.out b/compiler/testData/cli/jvm/jsr305MigrationIgnore.out index 6a6ee78e833..ca098ea8832 100644 --- a/compiler/testData/cli/jvm/jsr305MigrationIgnore.out +++ b/compiler/testData/cli/jvm/jsr305MigrationIgnore.out @@ -1,4 +1,7 @@ -compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: type mismatch: inferred type is Nothing? but String was expected annotated.foo(null) ^ +compiler/testData/cli/jvm/jsr305Migration.kt:4:5: warning: unsafe use of a nullable receiver of type String? + annotated.nullable().length + ^ OK diff --git a/compiler/testData/cli/jvm/jsr305MigrationWarn.out b/compiler/testData/cli/jvm/jsr305MigrationWarn.out index aa2bec44ea5..2e67cc253e5 100644 --- a/compiler/testData/cli/jvm/jsr305MigrationWarn.out +++ b/compiler/testData/cli/jvm/jsr305MigrationWarn.out @@ -1,7 +1,10 @@ -compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Migration.kt:2:19: warning: type mismatch: inferred type is Nothing? but String was expected annotated.foo(null) ^ -compiler/testData/cli/jvm/jsr305Migration.kt:3:19: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Migration.kt:3:19: warning: type mismatch: inferred type is Nothing? but String was expected annotated.bar(null) ^ +compiler/testData/cli/jvm/jsr305Migration.kt:4:5: warning: unsafe use of a nullable receiver of type String? + annotated.nullable().length + ^ OK diff --git a/compiler/testData/cli/jvm/jsr305NoFlag.out b/compiler/testData/cli/jvm/jsr305NoFlag.out index 1d7080a67e5..401112119da 100644 --- a/compiler/testData/cli/jvm/jsr305NoFlag.out +++ b/compiler/testData/cli/jvm/jsr305NoFlag.out @@ -1,4 +1,4 @@ -compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected a.foo(null) ^ OK diff --git a/compiler/testData/cli/jvm/jsr305Warn.out b/compiler/testData/cli/jvm/jsr305Warn.out index 1d7080a67e5..401112119da 100644 --- a/compiler/testData/cli/jvm/jsr305Warn.out +++ b/compiler/testData/cli/jvm/jsr305Warn.out @@ -1,4 +1,4 @@ -compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: expected type does not accept nulls in Java, but the value may be null in Kotlin +compiler/testData/cli/jvm/jsr305Usage.kt:2:11: warning: type mismatch: inferred type is Nothing? but String was expected a.foo(null) ^ OK diff --git a/compiler/testData/foreignAnnotations/tests/androidRecently.kt b/compiler/testData/foreignAnnotations/tests/androidRecently.kt index 5a2e276604d..b3fb86ddab4 100644 --- a/compiler/testData/foreignAnnotations/tests/androidRecently.kt +++ b/compiler/testData/foreignAnnotations/tests/androidRecently.kt @@ -27,18 +27,18 @@ public class A { fun main(a: A, a1: A) { a.foo("", null)?.length - a.foo("", null).length - a.foo(null, "").length + a.foo("", null).length + a.foo(null, "").length a.bar().length a.bar()!!.length a.field?.length - a.field.length + a.field.length - a.baz("").length + a.baz("").length a.baz("")?.length - a.baz(null).length + a.baz(null).length a1.baz("")!!.length a1.baz(null)!!.length @@ -51,4 +51,3 @@ fun main(a: A, a1: A) { a.baz2(null)?.length a.baz2(null)!!.length } - diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/arithmetic.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/arithmetic.kt index 2d459415d0c..afcf67e81f6 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/arithmetic.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/arithmetic.kt @@ -18,15 +18,15 @@ fun test() { var platformJ = J.staticJ +platformNN - +platformN + +platformN +platformJ ++platformNN - ++platformN + ++platformN ++platformJ platformNN++ - platformN++ + platformN++ platformJ++ 1 + platformNN @@ -34,7 +34,7 @@ fun test() { 1 + platformJ platformNN + 1 - platformN + 1 + platformN + 1 platformJ + 1 1 plus platformNN @@ -42,10 +42,10 @@ fun test() { 1 plus platformJ platformNN plus 1 - platformN plus 1 + platformN plus 1 platformJ plus 1 platformNN += 1 - platformN += 1 + platformN += 1 platformJ += 1 -} \ No newline at end of file +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/array.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/array.kt index 2b6861b617f..7fa13399fa1 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/array.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/array.kt @@ -18,10 +18,10 @@ fun test() { val platformJ = J.staticJ platformNN[0] - platformN[0] + platformN[0] platformJ[0] platformNN[0] = 1 - platformN[0] = 1 + platformN[0] = 1 platformJ[0] = 1 } diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/conditions.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/conditions.kt index 81ba1f1f6a7..ca1893a3de0 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/conditions.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/conditions.kt @@ -39,6 +39,6 @@ fun test() { platformJ || false !platformNN - !platformN + !platformN !platformJ -} \ No newline at end of file +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/delegatedProperties.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/delegatedProperties.kt index 0858a0ea375..a1a1271e667 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/delegatedProperties.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/delegatedProperties.kt @@ -19,5 +19,5 @@ public class J { // FILE: k.kt var A by J.staticNN -var B by J.staticN -var C by J.staticJ \ No newline at end of file +var B by J.staticN +var C by J.staticJ diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceExtension.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceExtension.kt index 9fdfd52376b..2b2597e624c 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceExtension.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceExtension.kt @@ -19,7 +19,7 @@ fun test() { val platformJ = J.staticJ platformNN.foo() - platformN.foo() + platformN.foo() platformJ.foo() with(platformNN) { diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceMember.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceMember.kt index 67d082641fa..c2a7b613c5e 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceMember.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/derefenceMember.kt @@ -24,7 +24,7 @@ fun test() { val platformJ = J.staticJ platformNN.foo() - platformN.foo() + platformN.foo() platformJ.foo() with(platformNN) { diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/for.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/for.kt index 622494e0f05..aa9903cad3a 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/for.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/for.kt @@ -20,7 +20,6 @@ fun test() { val platformJ = J.staticJ for (x in platformNN) {} - for (x in platformN) {} + for (x in platformN) {} for (x in platformJ) {} } - diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/invoke.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/invoke.kt index 2386c379e53..f139bb0c8ac 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/invoke.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/invoke.kt @@ -18,6 +18,6 @@ public class J { fun test() { J.staticNN() - J.staticN() + J.staticN() J.staticJ() -} \ No newline at end of file +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/kt6829.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/kt6829.kt index 665a2b7add2..1ddfc4b8ed5 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/kt6829.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/kt6829.kt @@ -15,9 +15,9 @@ public class J { fun foo(collection: Collection) { val mapped = collection.map { it.method() } - mapped[0].length + mapped[0].length } public fun Iterable.map(transform: (T) -> R): List { null!! -} \ No newline at end of file +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/multiDeclaration.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/multiDeclaration.kt index e68c2d6dcca..da222f94377 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/multiDeclaration.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/multiDeclaration.kt @@ -24,6 +24,6 @@ fun test() { val platformJ = J.staticJ val (a1, b1) = platformNN - val (a2, b2) = platformN + val (a2, b2) = platformN val (a3, b3) = platformJ -} \ No newline at end of file +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/primitiveArray.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/primitiveArray.kt index bf1d07fc73c..41df7a664ac 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/primitiveArray.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/fromPlatformTypes/primitiveArray.kt @@ -18,11 +18,10 @@ fun test() { val platformJ = J.staticJ platformNN[0] - platformN[0] + platformN[0] platformJ[0] platformNN[0] = 1 - platformN[0] = 1 + platformN[0] = 1 platformJ[0] = 1 } - diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt index 0f9894dc652..e3925d20cb4 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/nullabilityNicknames.kt @@ -79,15 +79,15 @@ public class A { fun main(a: A) { a.foo("", null)?.length - a.foo("", null).length - a.foo(null, "").length + a.foo("", null).length + a.foo(null, "").length - a.baz("", null).length - a.baz(null, "").length + a.baz("", null).length + a.baz(null, "").length a.bar().length a.bar()!!.length a.field?.length - a.field.length + a.field.length } diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt index e23b1adc3ff..430fca93cf7 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/fieldsAreNullable.kt @@ -50,7 +50,7 @@ fun main(a: A) { a.bar()!!.length a.field?.length - a.field.length + a.field.length a.field = null a.nonNullField?.length diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt index 0783c21b5a9..dfa676a71d5 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/overridingDefaultQualifier.kt @@ -134,7 +134,7 @@ fun main(a: A, b: A.B, c: A.C) { a.foo("", null).length a.foo(null, "").length - a.foobar(null, "").length + a.foobar(null, "").length a.foobar("", null)?.length a.bar().length @@ -149,17 +149,17 @@ fun main(a: A, b: A.B, c: A.C) { // b b.foo("", null)?.length - b.foo("", null).length - b.foo(null, "").length + b.foo("", null).length + b.foo(null, "").length b.foobar(null, "").length b.foobar("", null)?.length - b.bar().length + b.bar().length b.bar()!!.length b.field?.length - b.field.length + b.field.length b.baz().get(0) b.baz()!!.get(0).get(0) @@ -170,14 +170,14 @@ fun main(a: A, b: A.B, c: A.C) { c.foo("", null).length c.foo(null, "").length - c.foobar(null, "").length + c.foobar(null, "").length c.foobar("", null)?.length c.bar().length c.bar()!!.length c.field?.length - c.field.length + c.field.length c.baz().get(0) c.baz()!!.get(0).get(0) diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullable.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullable.kt index 215943844f7..bc0582d04d6 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullable.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullable.kt @@ -69,7 +69,7 @@ public class A { fun main(a: A) { a.foo("", null)?.length a.foo("", null).length - a.foo(null, "").length + a.foo(null, "").length a.bar().length a.bar()!!.length @@ -77,7 +77,7 @@ fun main(a: A) { a.field?.length a.field.length - a.baz().get(0) + ?)!>a.baz().get(0) a.baz()!!.get(0).get(0) a.baz()!!.get(0)?.get(0) } diff --git a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullablePackage.kt b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullablePackage.kt index 08aca8a3b15..a6d55046292 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullablePackage.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305/nullabilityWarnings/typeQualifierDefault/springNullablePackage.kt @@ -83,7 +83,7 @@ fun main(a: test.A) { a.field?.length a.field.length - a.baz().get(0) + a.baz().get(0) a.baz()!!.get(0).get(0) a.baz()!!.get(0)?.get(0) } diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationError.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationError.kt index 8e2c6cf5260..d881422d507 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationError.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationError.kt @@ -64,14 +64,14 @@ fun main(a: A) { a.field.length a.foo2("", null)?.length - a.foo2("", null).length - a.foo2(null, "").length + a.foo2("", null).length + a.foo2(null, "").length a.bar2().length a.bar2()!!.length a.field2?.length - a.field2.length + a.field2.length a.field3?.length a.field3.length diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationIgnore.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationIgnore.kt index d3564fc12ea..d0557e9655e 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationIgnore.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/migrationIgnore.kt @@ -46,12 +46,12 @@ fun main(a: A) { a.field.length a.foo2("", null)?.length - a.foo2("", null).length - a.foo2(null, "").length + a.foo2("", null).length + a.foo2(null, "").length a.bar2().length a.bar2()!!.length a.field2?.length - a.field2.length + a.field2.length } diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/overrideConflicts.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/overrideConflicts.kt index ef21f56308d..649a59425dc 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/overrideConflicts.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/overrideConflicts.kt @@ -66,7 +66,7 @@ fun main(b: B, c: C) { b.foo2()?.length b.foo3().length b.foo3()?.length - b.foo4().length + b.foo4().length b.foo4()?.length b.bar(null) @@ -82,4 +82,4 @@ fun main(b: B, c: C) { c.foo4()?.length c.bar4(null) c.bar4("") -} \ No newline at end of file +} diff --git a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/stateRefinement.kt b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/stateRefinement.kt index 284ae7f9ce4..f5669b101d9 100644 --- a/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/stateRefinement.kt +++ b/compiler/testData/foreignAnnotations/tests/jsr305NullabilityWarnings/migration/stateRefinement.kt @@ -36,14 +36,14 @@ public class A { fun main(a: A) { a.foo("", null)?.length - a.foo("", null).length - a.foo(null, "").length + a.foo("", null).length + a.foo(null, "").length a.bar().length a.bar()!!.length a.field?.length - a.field.length + a.field.length a.foo2("", null)?.length a.foo2("", null).length diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java index 7fb03dd325b..cb62b3d0a5d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/IdeErrorMessages.java @@ -34,6 +34,7 @@ import static org.jetbrains.kotlin.idea.highlighter.HtmlTabledDescriptorRenderer import static org.jetbrains.kotlin.idea.highlighter.IdeRenderers.*; import static org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.ACCIDENTAL_OVERRIDE; import static org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.CONFLICTING_JVM_DECLARATIONS; +import static org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS; /** @@ -63,6 +64,9 @@ public class IdeErrorMessages { MAP.put(TYPE_MISMATCH, "Type mismatch.
Required:{0}
Found:{1}
", HTML_RENDER_TYPE, HTML_RENDER_TYPE); + MAP.put(NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, "Type mismatch.
Required:{0}
Found:{1}
", + HTML_RENDER_TYPE, HTML_RENDER_TYPE); + MAP.put(TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS, "Type mismatch.
Required:{0}
Found:{1}

\n" + "Projected type {2} restricts use of
\n{3}\n",