From e6594ed5b110c7458ae22b4cfcb46327611d61ed Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 26 Dec 2012 13:53:42 +0400 Subject: [PATCH] KT-2883 Type inference fails due to non-Unit value returned #KT-2883 fixed --- .../expressions/ExpressionTypingServices.java | 2 +- .../tests/inference/regressions/kt2883.kt | 32 +++++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 5 +++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/inference/regressions/kt2883.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java index 9dd1d6541cb..5118358f760 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingServices.java @@ -368,7 +368,7 @@ public class ExpressionTypingServices { mismatchFound[0] = true; } if (TYPE_INFERENCE_ERRORS.contains(diagnostic.getFactory()) && - PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetQualifiedExpression.class, false) == expressionToWatch) { + PsiTreeUtil.isAncestor(expressionToWatch, diagnostic.getPsiElement(), false)) { mismatchFound[0] = true; } super.report(diagnostic); diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2883.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2883.kt new file mode 100644 index 00000000000..9257e38298d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2883.kt @@ -0,0 +1,32 @@ +//KT-2883 Type inference fails due to non-Unit value returned +package a + +public fun doAction(action : () -> Unit){ +} + +class Y(val itemToString: (TItem) -> String){ +} + +fun bar(context : Y) : TItem{ +} + +fun foo(){ + val stringToString : (String) -> String = { it } + doAction({bar(Y(stringToString))}) +} + +fun bar(t: T): T = t + +fun test() { + + doAction { bar(12) } + + val u: Unit = bar(11) +} + +fun testWithoutInference(col: MutableCollection) { + + doAction { col.add(2) } + + val u: Unit = col.add(2) +} \ 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 b5a8700f973..8355a856709 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2222,6 +2222,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2842.kt"); } + @TestMetadata("kt2883.kt") + public void testKt2883() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2883.kt"); + } + @TestMetadata("kt3007.kt") public void testKt3007() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3007.kt");