From 845b6f7d7e0c67cc94a37ebe1f7ecad6b913026a Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 16 Sep 2013 16:47:37 +0400 Subject: [PATCH] fixed bug NULL_FOR_NONNULL_TYPE can represent type mismatch error as well (later the whole method 'makeTraceInterceptingTypeMismatch' should be removed) --- .../lang/types/expressions/ExpressionTypingUtils.java | 2 +- .../diagnostics/tests/functionLiterals/returnNull.kt | 10 ++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index d09f8bd9f44..ebc9b2c9f9f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -462,7 +462,7 @@ public class ExpressionTypingUtils { @Override public void report(@NotNull Diagnostic diagnostic) { AbstractDiagnosticFactory factory = diagnostic.getFactory(); - if ((factory == TYPE_MISMATCH || factory == CONSTANT_EXPECTED_TYPE_MISMATCH) + if ((factory == TYPE_MISMATCH || factory == CONSTANT_EXPECTED_TYPE_MISMATCH || factory == NULL_FOR_NONNULL_TYPE) && diagnostic.getPsiElement() == expressionToWatch) { mismatchFound[0] = true; } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt b/compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt new file mode 100644 index 00000000000..8110dc40a3c --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt @@ -0,0 +1,10 @@ +package m + +trait Element + +fun test(handlers: MapUnit>) { + + handlers.getOrElse("name", { null }) +} + +fun Map.getOrElse(key: K, defaultValue: ()-> V) : V = throw Exception("$key $defaultValue") \ 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 8acbcaa80ac..4fd94896cba 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2685,6 +2685,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt"); } + @TestMetadata("returnNull.kt") + public void testReturnNull() throws Exception { + doTest("compiler/testData/diagnostics/tests/functionLiterals/returnNull.kt"); + } + @TestMetadata("unusedLiteral.kt") public void testUnusedLiteral() throws Exception { doTest("compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt");