diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java index 0ad46eca9b7..3941428a34d 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/autocasts/DataFlowValueFactory.java @@ -62,7 +62,7 @@ public class DataFlowValueFactory { } 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 diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/senslessComparisonWithNullOnTypeParameters.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/senslessComparisonWithNullOnTypeParameters.kt new file mode 100644 index 00000000000..f4c6fb9ec8a --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/senslessComparisonWithNullOnTypeParameters.kt @@ -0,0 +1,16 @@ +// The type checker used to think that T is not null no matter what the upper bound + +fun nullableUpperBound(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: T, ind: INDIRECT) { + if (t == null) {} // still a warning + if (t != null) {} // still a warning + if (ind == null) {} // still a warning + if (ind != null) {} // still a warning +} + diff --git a/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.kt b/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.kt index 1b52fb5f78a..002bcd0def1 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/redundantNullableInSupertype.kt @@ -3,6 +3,6 @@ trait X: Any?? { } fun interaction(t: T) { - if (t == null) {} + if (t == null) {} } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 2712ffdb6de..957d503ea77 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2286,6 +2286,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage 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")