If t is of type T, comparison (t == null) may be true. No warning in this case
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@ public class DataFlowValueFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Nullability getImmanentNullability(JetType type) {
|
private Nullability getImmanentNullability(JetType type) {
|
||||||
return type.isNullable() ? Nullability.UNKNOWN : Nullability.NOT_NULL;
|
return type.isNullable() || TypeUtils.hasNullableSuperType(type) ? Nullability.UNKNOWN : Nullability.NOT_NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
// The type checker used to think that T is not null no matter what the upper bound
|
||||||
|
|
||||||
|
fun nullableUpperBound<T, INDIRECT: T>(t: T, ind: INDIRECT) {
|
||||||
|
if (t == null) {} // was a warning
|
||||||
|
if (t != null) {} // was a warning
|
||||||
|
if (ind == null) {} // was a warning
|
||||||
|
if (ind != null) {} // was a warning
|
||||||
|
}
|
||||||
|
|
||||||
|
fun notNullUpperBound<T: Any, INDIRECT: T>(t: T, ind: INDIRECT) {
|
||||||
|
if (<!SENSELESS_COMPARISON!>t == null<!>) {} // still a warning
|
||||||
|
if (<!SENSELESS_COMPARISON!>t != null<!>) {} // still a warning
|
||||||
|
if (<!SENSELESS_COMPARISON!>ind == null<!>) {} // still a warning
|
||||||
|
if (<!SENSELESS_COMPARISON!>ind != null<!>) {} // still a warning
|
||||||
|
}
|
||||||
|
|
||||||
@@ -3,6 +3,6 @@ trait X: Any<!NULLABLE_SUPERTYPE!>?<!><!REDUNDANT_NULLABLE!>?<!> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun interaction<T>(t: T) {
|
fun interaction<T>(t: T) {
|
||||||
if (<!SENSELESS_COMPARISON!>t == null<!>) {}
|
if (t == null) {}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2286,6 +2286,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/SenselessNullInWhen.kt");
|
doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/SenselessNullInWhen.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("senslessComparisonWithNullOnTypeParameters.kt")
|
||||||
|
public void testSenslessComparisonWithNullOnTypeParameters() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/senslessComparisonWithNullOnTypeParameters.kt");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/tests/nullableTypes")
|
@TestMetadata("compiler/testData/diagnostics/tests/nullableTypes")
|
||||||
|
|||||||
Reference in New Issue
Block a user