HL API: Fix argument mapping for lambda arguments (+ more tests).

This commit is contained in:
Mark Punzalan
2021-08-21 08:42:27 +00:00
committed by TeamCityServer
parent 20f297aaf7
commit 306a035c68
13 changed files with 85 additions and 6 deletions
@@ -180,10 +180,10 @@ internal class KtFirCallResolver(
val ktArgumentMapping = LinkedHashMap<KtExpression, KtValueParameterSymbol>()
argumentMapping?.let {
fun FirExpression.findKtExpression(): KtExpression? {
// For spread and named arguments, the source is the KtValueArgument.
// For spread, named, and lambda arguments, the source is the KtValueArgument.
// For other arguments (including array indices), the source is the KtExpression.
return when (this) {
is FirNamedArgumentExpression, is FirSpreadArgumentExpression ->
is FirNamedArgumentExpression, is FirSpreadArgumentExpression, is FirLambdaArgumentExpression ->
realPsi.safeAs<KtValueArgument>()?.getArgumentExpression()
else -> realPsi as? KtExpression
}
@@ -0,0 +1,7 @@
fun function(a: Int, b: (String) -> Boolean) {}
fun call() {
<expr>function(1) { s -> true }</expr>
}
// CALL: KtFunctionCall: targetFunction = /function(a: kotlin.Int, b: (kotlin.String) -> kotlin.Boolean): kotlin.Unit
@@ -0,0 +1,3 @@
KtFunctionCall:
argumentMapping = { 1 -> (a: kotlin.Int), { s -> true } -> (b: kotlin.Function1<kotlin.String, kotlin.Boolean>) }
targetFunction = /function(a: kotlin.Int, b: kotlin.Function1<kotlin.String, kotlin.Boolean>): kotlin.Unit
@@ -0,0 +1,7 @@
fun function(a: Int, b: String) {}
fun call() {
<expr>function(b = "foo", a = 1)</expr>
}
// CALL: KtFunctionCall: targetFunction = /function(a: kotlin.Int, b: kotlin.String): kotlin.Unit
@@ -0,0 +1,3 @@
KtFunctionCall:
argumentMapping = { "foo" -> (b: kotlin.String), 1 -> (a: kotlin.Int) }
targetFunction = /function(a: kotlin.Int, b: kotlin.String): kotlin.Unit
@@ -0,0 +1,7 @@
fun function(a: Int, b: (String) -> Boolean) {}
fun call() {
<expr>function(1, { s -> true })</expr>
}
// CALL: KtFunctionCall: targetFunction = /function(a: kotlin.Int, b: (String) -> Boolean): kotlin.Unit
@@ -0,0 +1,3 @@
KtFunctionCall:
argumentMapping = { 1 -> (a: kotlin.Int), { s -> true } -> (b: kotlin.Function1<kotlin.String, kotlin.Boolean>) }
targetFunction = /function(a: kotlin.Int, b: kotlin.Function1<kotlin.String, kotlin.Boolean>): kotlin.Unit
@@ -0,0 +1,8 @@
fun function(vararg a: Int) {}
fun call() {
val args = intArrayOf(1, 2, 3)
<expr>function(*args)</expr>
}
// CALL: KtFunctionCall: targetFunction = /function(vararg a: kotlin.IntArray): kotlin.Unit
@@ -0,0 +1,3 @@
KtFunctionCall:
argumentMapping = { args -> (vararg a: kotlin.IntArray) }
targetFunction = /function(vararg a: kotlin.IntArray): kotlin.Unit
@@ -0,0 +1,7 @@
fun function(vararg a: Int) {}
fun call() {
<expr>function(1, 2, 3)</expr>
}
// CALL: KtFunctionCall: targetFunction = /function(vararg a: kotlin.IntArray): kotlin.Unit
@@ -0,0 +1,3 @@
KtFunctionCall:
argumentMapping = { 1 -> (vararg a: kotlin.IntArray), 2 -> (vararg a: kotlin.IntArray), 3 -> (vararg a: kotlin.IntArray) }
targetFunction = /function(vararg a: kotlin.IntArray): kotlin.Unit
@@ -61,13 +61,11 @@ private fun KtCall.stringRepresentation(): String {
append("<receiver>: ${receiver.type.render()}")
if (valueParameters.isNotEmpty()) append(", ")
}
valueParameters.joinTo(this) { parameter ->
"${parameter.name}: ${parameter.annotatedType.type.render()}"
}
valueParameters.joinTo(this) { it.stringValue() }
append(")")
append(": ${annotatedType.type.render()}")
}
is KtValueParameterSymbol -> "$name: ${annotatedType.type.render()}"
is KtValueParameterSymbol -> "${if (isVararg) "vararg " else ""}$name: ${annotatedType.type.render()}"
is KtSuccessCallTarget -> symbol.stringValue()
is KtErrorCallTarget -> "ERR<${this.diagnostic.defaultMessage}, [${candidates.joinToString { it.stringValue() }}]>"
is Boolean -> toString()
@@ -54,6 +54,36 @@ public class ResolveCallTestGenerated extends AbstractResolveCallTest {
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/functionCallInTheSameFile.kt");
}
@Test
@TestMetadata("functionCallWithLambdaArgument.kt")
public void testFunctionCallWithLambdaArgument() throws Exception {
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/functionCallWithLambdaArgument.kt");
}
@Test
@TestMetadata("functionCallWithNamedArgument.kt")
public void testFunctionCallWithNamedArgument() throws Exception {
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/functionCallWithNamedArgument.kt");
}
@Test
@TestMetadata("functionCallWithNonTrailingLambdaArgument.kt")
public void testFunctionCallWithNonTrailingLambdaArgument() throws Exception {
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/functionCallWithNonTrailingLambdaArgument.kt");
}
@Test
@TestMetadata("functionCallWithSpreadArgument.kt")
public void testFunctionCallWithSpreadArgument() throws Exception {
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/functionCallWithSpreadArgument.kt");
}
@Test
@TestMetadata("functionCallWithVarargArgument.kt")
public void testFunctionCallWithVarargArgument() throws Exception {
runTest("idea/idea-frontend-fir/testData/analysisSession/resolveCall/functionCallWithVarargArgument.kt");
}
@Test
@TestMetadata("functionWithReceiverCall.kt")
public void testFunctionWithReceiverCall() throws Exception {