From ca88a01e1dc09f5146df9a1c3aca8cac5b30b00b Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Wed, 5 Jun 2013 20:31:47 +0400 Subject: [PATCH] no 'dangling function literal' check for nested calls --- .../jet/lang/resolve/calls/CallResolver.java | 3 ++- .../DanglingFunctionLiteral.kt | 0 .../NoDanglingFunctionLiteralForNestedCalls.kt | 11 +++++++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 15 ++++++++++----- 4 files changed, 23 insertions(+), 6 deletions(-) rename compiler/testData/diagnostics/tests/{ => functionLiterals}/DanglingFunctionLiteral.kt (100%) create mode 100644 compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java index 39bf46044f7..d40bfda16b4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CallResolver.java @@ -477,7 +477,8 @@ public class CallResolver { // } ImmutableSet someFailed = ImmutableSet.of(OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES, OverloadResolutionResults.Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH); - if (someFailed.contains(results.getResultCode()) && !task.call.getFunctionLiteralArguments().isEmpty()) { + if (someFailed.contains(results.getResultCode()) && !task.call.getFunctionLiteralArguments().isEmpty() + && task.resolveMode == ResolveMode.TOP_LEVEL_CALL) { //For nested calls there are no such cases // We have some candidates that failed for some reason // And we have a suspect: the function literal argument // Now, we try to remove this argument and see if it helps diff --git a/compiler/testData/diagnostics/tests/DanglingFunctionLiteral.kt b/compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt similarity index 100% rename from compiler/testData/diagnostics/tests/DanglingFunctionLiteral.kt rename to compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt diff --git a/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt b/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt new file mode 100644 index 00000000000..655667c2aa3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt @@ -0,0 +1,11 @@ +package baz + +fun test() { + foo(1) {} + + foo( foo(1) {} ) //here +} + +fun foo(i: Int) {} + +fun foo() : (i : () -> Unit) -> Unit = {} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 7c04c0905b5..0d258ad49d2 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -169,11 +169,6 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/CyclicHierarchy.kt"); } - @TestMetadata("DanglingFunctionLiteral.kt") - public void testDanglingFunctionLiteral() throws Exception { - doTest("compiler/testData/diagnostics/tests/DanglingFunctionLiteral.kt"); - } - @TestMetadata("DefaultValuesTypechecking.kt") public void testDefaultValuesTypechecking() throws Exception { doTest("compiler/testData/diagnostics/tests/DefaultValuesTypechecking.kt"); @@ -2300,6 +2295,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/functionLiterals"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("DanglingFunctionLiteral.kt") + public void testDanglingFunctionLiteral() throws Exception { + doTest("compiler/testData/diagnostics/tests/functionLiterals/DanglingFunctionLiteral.kt"); + } + @TestMetadata("ExpectedParameterTypeMismatchVariance.kt") public void testExpectedParameterTypeMismatchVariance() throws Exception { doTest("compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.kt"); @@ -2315,6 +2315,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt"); } + @TestMetadata("NoDanglingFunctionLiteralForNestedCalls.kt") + public void testNoDanglingFunctionLiteralForNestedCalls() throws Exception { + doTest("compiler/testData/diagnostics/tests/functionLiterals/NoDanglingFunctionLiteralForNestedCalls.kt"); + } + @TestMetadata("unusedLiteral.kt") public void testUnusedLiteral() throws Exception { doTest("compiler/testData/diagnostics/tests/functionLiterals/unusedLiteral.kt");