Refine diagnostics for nullability migration warnings
#KT-24911 Fixed
This commit is contained in:
+33
-24
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -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,
|
||||
|
||||
+4
-19
@@ -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<KtAnnotationEntry> 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<KtElement, NullabilityInformationSource, NullabilityInformationSource> NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
|
||||
DiagnosticFactory2<KtElement, KotlinType, KotlinType> NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
|
||||
= DiagnosticFactory2.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<KtElement, KotlinType> RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS
|
||||
= DiagnosticFactory1.create(WARNING);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
{
|
||||
|
||||
+6
-1
@@ -5,4 +5,9 @@ public class Annotated {
|
||||
|
||||
public void bar(@MyMigrationNonnull String x) {
|
||||
}
|
||||
}
|
||||
|
||||
@MyNullable
|
||||
public String nullable() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
+1
-1
@@ -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
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
fun test(annotated: Annotated) {
|
||||
annotated.foo(null)
|
||||
annotated.bar(null)
|
||||
}
|
||||
annotated.nullable().length
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
+4
-1
@@ -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
|
||||
|
||||
+5
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -27,18 +27,18 @@ public class A<T> {
|
||||
|
||||
fun main(a: A<String>, a1: A<String?>) {
|
||||
a.foo("", null)?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS(String?)!>a.foo("", null)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS(String; Nothing?)!>null<!>, "")<!>.length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("")<!>.length
|
||||
a.baz("")?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)<!>.length
|
||||
|
||||
a1.baz("")!!.length
|
||||
a1.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)!!.length
|
||||
@@ -51,4 +51,3 @@ fun main(a: A<String>, a1: A<String?>) {
|
||||
a.baz2(null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.baz2(null)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -18,15 +18,15 @@ fun test() {
|
||||
var platformJ = J.staticJ
|
||||
|
||||
+platformNN
|
||||
+<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
+<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
+platformJ
|
||||
|
||||
++platformNN
|
||||
++<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
++<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
++platformJ
|
||||
|
||||
platformNN++
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>++
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>++
|
||||
platformJ++
|
||||
|
||||
1 + platformNN
|
||||
@@ -34,7 +34,7 @@ fun test() {
|
||||
1 + platformJ
|
||||
|
||||
platformNN + 1
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> + 1
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> + 1
|
||||
platformJ + 1
|
||||
|
||||
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformNN
|
||||
@@ -42,10 +42,10 @@ fun test() {
|
||||
1 <!INFIX_MODIFIER_REQUIRED!>plus<!> platformJ
|
||||
|
||||
platformNN <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
platformJ <!INFIX_MODIFIER_REQUIRED!>plus<!> 1
|
||||
|
||||
platformNN += 1
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> += 1
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!> += 1
|
||||
platformJ += 1
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -18,10 +18,10 @@ fun test() {
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN[0]
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0]
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0]
|
||||
platformJ[0]
|
||||
|
||||
platformNN[0] = 1
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0] = 1
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0] = 1
|
||||
platformJ[0] = 1
|
||||
}
|
||||
|
||||
+2
-2
@@ -39,6 +39,6 @@ fun test() {
|
||||
platformJ || false
|
||||
|
||||
!platformNN
|
||||
!<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
!<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
!platformJ
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -19,5 +19,5 @@ public class J {
|
||||
// FILE: k.kt
|
||||
|
||||
var A by J.staticNN
|
||||
var B by <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>J.staticN<!>
|
||||
var C by J.staticJ
|
||||
var B by <!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>J.staticN<!>
|
||||
var C by J.staticJ
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ fun test() {
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN.foo()
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>.foo()
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>.foo()
|
||||
platformJ.foo()
|
||||
|
||||
with(platformNN) {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ fun test() {
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN.foo()
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>.foo()
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>.foo()
|
||||
platformJ.foo()
|
||||
|
||||
with(platformNN) {
|
||||
|
||||
Vendored
+1
-2
@@ -20,7 +20,6 @@ fun test() {
|
||||
val platformJ = J.staticJ
|
||||
|
||||
for (x in platformNN) {}
|
||||
for (x in <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>) {}
|
||||
for (x in <!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>) {}
|
||||
for (x in platformJ) {}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -18,6 +18,6 @@ public class J {
|
||||
|
||||
fun test() {
|
||||
J.staticNN()
|
||||
J.<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>staticN<!>()
|
||||
J.<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>staticN<!>()
|
||||
J.staticJ()
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -15,9 +15,9 @@ public class J {
|
||||
|
||||
fun foo(collection: Collection<J>) {
|
||||
val mapped = collection.map { it.method() }
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>mapped[0]<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>mapped[0]<!>.length
|
||||
}
|
||||
|
||||
public fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R> {
|
||||
null!!
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -24,6 +24,6 @@ fun test() {
|
||||
val platformJ = J.staticJ
|
||||
|
||||
val (a1, b1) = platformNN
|
||||
val (a2, b2) = <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
val (a2, b2) = <!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>
|
||||
val (a3, b3) = platformJ
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -18,11 +18,10 @@ fun test() {
|
||||
val platformJ = J.staticJ
|
||||
|
||||
platformNN[0]
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0]
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0]
|
||||
platformJ[0]
|
||||
|
||||
platformNN[0] = 1
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0] = 1
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>platformN<!>[0] = 1
|
||||
platformJ[0] = 1
|
||||
}
|
||||
|
||||
|
||||
Vendored
+5
-5
@@ -79,15 +79,15 @@ public class A {
|
||||
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("", null)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz("", null)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ fun main(a: A) {
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
a.field = null
|
||||
|
||||
a.nonNullField<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
+7
-7
@@ -134,7 +134,7 @@ fun main(a: A, b: A.B, c: A.C) {
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foobar(null, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foobar(null, "")<!>.length
|
||||
a.foobar("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
|
||||
|
||||
a.bar().length
|
||||
@@ -149,17 +149,17 @@ fun main(a: A, b: A.B, c: A.C) {
|
||||
|
||||
// b
|
||||
b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo(null, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo("", <!NULL_FOR_NONNULL_TYPE!>null<!>)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo(null, "")<!>.length
|
||||
|
||||
b.foobar(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
b.foobar("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.bar()<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.bar()<!>.length
|
||||
b.bar()!!.length
|
||||
|
||||
b.field?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.field<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.field<!>.length
|
||||
|
||||
b.baz()<!UNSAFE_CALL!>.<!>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(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>c.foobar(null, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>c.foobar(null, "")<!>.length
|
||||
c.foobar("", null)?.length
|
||||
|
||||
c.bar().length
|
||||
c.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
c.field?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>c.field<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>c.field<!>.length
|
||||
|
||||
c.baz()<!UNSAFE_CALL!>.<!>get(0)
|
||||
c.baz()!!.get(0).get(0)
|
||||
|
||||
+2
-2
@@ -69,7 +69,7 @@ public class A {
|
||||
fun main(a: A) {
|
||||
a.foo("", null)<!UNNECESSARY_SAFE_CALL!>?.<!>length
|
||||
a.foo("", null).length
|
||||
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "").length
|
||||
a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS(String; Nothing?)!>null<!>, "").length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
@@ -77,7 +77,7 @@ fun main(a: A) {
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz()<!>.get(0)
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS(MutableList<String!>?)!>a.baz()<!>.get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ fun main(a: test.A) {
|
||||
a.field?.length
|
||||
a.field.length
|
||||
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz()<!>.get(0)
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.baz()<!>.get(0)
|
||||
a.baz()!!.get(0).get(0)
|
||||
a.baz()!!.get(0)?.get(0)
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -64,14 +64,14 @@ fun main(a: A) {
|
||||
a.field<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2("", null)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2(null, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2("", null)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2(null, "")<!>.length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()!!.length
|
||||
|
||||
a.field2?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field2<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field2<!>.length
|
||||
|
||||
a.field3?.length
|
||||
a.field3<!UNSAFE_CALL!>.<!>length
|
||||
|
||||
Vendored
+3
-3
@@ -46,12 +46,12 @@ fun main(a: A) {
|
||||
a.field.length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2("", null)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2("", null)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo2(<!NULL_FOR_NONNULL_TYPE!>null<!>, "")<!>.length
|
||||
|
||||
a.bar2().length
|
||||
a.bar2()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field2?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field2<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field2<!>.length
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -66,7 +66,7 @@ fun main(b: B, c: C) {
|
||||
b.foo2()?.length
|
||||
b.foo3()<!UNSAFE_CALL!>.<!>length
|
||||
b.foo3()?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo4()<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>b.foo4()<!>.length
|
||||
b.foo4()?.length
|
||||
|
||||
b.bar(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
@@ -82,4 +82,4 @@ fun main(b: B, c: C) {
|
||||
c.foo4()?.length
|
||||
c.bar4(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
c.bar4("")
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -36,14 +36,14 @@ public class A {
|
||||
|
||||
fun main(a: A) {
|
||||
a.foo("", null)?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo("", null)<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.foo(<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>, "")<!>.length
|
||||
|
||||
a.bar().length
|
||||
a.bar()<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>.length
|
||||
|
||||
a.field?.length
|
||||
<!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
<!RECEIVER_NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>a.field<!>.length
|
||||
|
||||
a.foo2("", null)?.length
|
||||
a.foo2("", null).length
|
||||
|
||||
@@ -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, "<html>Type mismatch.<table><tr><td>Required:</td><td>{0}</td></tr><tr><td>Found:</td><td>{1}</td></tr></table></html>",
|
||||
HTML_RENDER_TYPE, HTML_RENDER_TYPE);
|
||||
|
||||
MAP.put(NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS, "<html>Type mismatch.<table><tr><td>Required:</td><td>{0}</td></tr><tr><td>Found:</td><td>{1}</td></tr></table></html>",
|
||||
HTML_RENDER_TYPE, HTML_RENDER_TYPE);
|
||||
|
||||
MAP.put(TYPE_MISMATCH_DUE_TO_TYPE_PROJECTIONS,
|
||||
"<html>Type mismatch.<table><tr><td>Required:</td><td>{0}</td></tr><tr><td>Found:</td><td>{1}</td></tr></table><br />\n" +
|
||||
"Projected type {2} restricts use of <br />\n{3}\n</html>",
|
||||
|
||||
Reference in New Issue
Block a user