Correct report of NO_VALUE_FOR_PARAMETER when function call contains no brackets and lambda at the end #KT-7813 Fixed
This commit is contained in:
@@ -90,7 +90,13 @@ fun Call.getValueArgumentsInParentheses(): List<ValueArgument> = valueArguments.
|
|||||||
|
|
||||||
fun KtCallElement.getValueArgumentsInParentheses(): List<ValueArgument> = valueArguments.filterArgsInParentheses()
|
fun KtCallElement.getValueArgumentsInParentheses(): List<ValueArgument> = 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")
|
@Suppress("UNCHECKED_CAST")
|
||||||
private fun List<ValueArgument?>.filterArgsInParentheses() = filter { it !is KtLambdaArgument } as List<ValueArgument>
|
private fun List<ValueArgument?>.filterArgsInParentheses() = filter { it !is KtLambdaArgument } as List<ValueArgument>
|
||||||
|
|||||||
+16
@@ -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
|
||||||
|
<!NO_VALUE_FOR_PARAMETER!>p<!> { 1 }
|
||||||
|
p(<!NO_VALUE_FOR_PARAMETER!>)<!> { 2 }
|
||||||
|
p(3) { 4 }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun bar(p: (String, Any, () -> String) -> Unit) {
|
||||||
|
// Errors except last call
|
||||||
|
<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>p<!> { "" }
|
||||||
|
p(<!NO_VALUE_FOR_PARAMETER, NO_VALUE_FOR_PARAMETER!>)<!> { "x" }
|
||||||
|
p("y"<!NO_VALUE_FOR_PARAMETER!>)<!> { "z" }
|
||||||
|
p("v", Any()) { "w" }
|
||||||
|
}
|
||||||
+4
@@ -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
|
||||||
@@ -6573,6 +6573,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
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")
|
@TestMetadata("kt2906.kt")
|
||||||
public void testKt2906() throws Exception {
|
public void testKt2906() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user