diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt index f71c8812555..8f3d31f69dd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/util/callUtil.kt @@ -90,7 +90,13 @@ fun Call.getValueArgumentsInParentheses(): List = valueArguments. fun KtCallElement.getValueArgumentsInParentheses(): List = valueArguments.filterArgsInParentheses() -fun Call.getValueArgumentListOrElement(): KtElement = valueArgumentList ?: calleeExpression ?: callElement +fun Call.getValueArgumentListOrElement(): KtElement = + if (this is CallTransformer.CallForImplicitInvoke) { + outerCall.getValueArgumentListOrElement() + } + else { + valueArgumentList ?: calleeExpression ?: callElement + } @Suppress("UNCHECKED_CAST") private fun List.filterArgsInParentheses() = filter { it !is KtLambdaArgument } as List diff --git a/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt b/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt new file mode 100644 index 00000000000..94939d8d40c --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt @@ -0,0 +1,16 @@ +// See KT-7813: Call to functional parameter with missing argument: no error detected but compiler crashes + +fun foo(p: (Int, () -> Int) -> Unit) { + // Errors except last call + p { 1 } + p() { 2 } + p(3) { 4 } +} + +fun bar(p: (String, Any, () -> String) -> Unit) { + // Errors except last call + p { "" } + p() { "x" } + p("y") { "z" } + p("v", Any()) { "w" } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.txt b/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.txt new file mode 100644 index 00000000000..49fc64ea389 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.txt @@ -0,0 +1,4 @@ +package + +public fun bar(/*0*/ p: (kotlin.String, kotlin.Any, () -> kotlin.String) -> kotlin.Unit): kotlin.Unit +public fun foo(/*0*/ p: (kotlin.Int, () -> kotlin.Int) -> kotlin.Unit): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index dfb828aacbd..66a40342938 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -6573,6 +6573,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("higherOrderCallMissingParameters.kt") + public void testHigherOrderCallMissingParameters() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/higherOrderCallMissingParameters.kt"); + doTest(fileName); + } + @TestMetadata("kt2906.kt") public void testKt2906() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");