From 0ccdf79051dafaec6beaba0e936fe72b87e29fb1 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 19 Sep 2012 15:21:45 +0400 Subject: [PATCH] no report 'UNNECESSARY_NOT_NULL_ASSERTION' on error types --- .../types/expressions/BasicExpressionTypingVisitor.java | 2 +- .../noUnnecessaryNotNullAssertionOnErrorType.kt | 7 +++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index efc5025c772..834753d89ea 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -885,7 +885,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { return typeInfo; } DataFlowInfo dataFlowInfo = typeInfo.getDataFlowInfo(); - if (isKnownToBeNotNull(baseExpression, context)) { + if (isKnownToBeNotNull(baseExpression, context) && !ErrorUtils.isErrorType(type)) { context.trace.report(UNNECESSARY_NOT_NULL_ASSERTION.on(operationSign, type)); } else { diff --git a/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt new file mode 100644 index 00000000000..ff08f2d31c3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt @@ -0,0 +1,7 @@ +package a + +fun foo() { + bar()!! +} + +fun bar() = aa \ 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 eddccd51d75..b5a48369cd4 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2098,6 +2098,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/kt362.kt"); } + @TestMetadata("noUnnecessaryNotNullAssertionOnErrorType.kt") + public void testNoUnnecessaryNotNullAssertionOnErrorType() throws Exception { + doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/noUnnecessaryNotNullAssertionOnErrorType.kt"); + } + @TestMetadata("NullableNothingIsExactlyNull.kt") public void testNullableNothingIsExactlyNull() throws Exception { doTest("compiler/testData/diagnostics/tests/nullabilityAndAutoCasts/NullableNothingIsExactlyNull.kt");