From 080a8326053d390fd228bddb90779bb82956c2c0 Mon Sep 17 00:00:00 2001 From: Stanislav Erokhin Date: Mon, 10 May 2021 12:09:02 +0200 Subject: [PATCH] Fix argument mapping for lambda arguments and default arguments Maybe for other elements ValueArgument itself used as SourceElement --- .../idea/fir/fe10/binding/CallAndResolverCallWrappers.kt | 6 ++++-- .../replaceContains/functionLiteralArgument.kt | 1 - .../replaceContains/functionLiteralArgument.kt.after | 1 - .../functionLiteralArgumentAfterSemicolon.kt | 1 - .../functionLiteralArgumentAfterSemicolon.kt.after | 1 - .../functionLiteralArgumentAtStartOfBlock.kt | 1 - .../functionLiteralArgumentAtStartOfBlock.kt.after | 1 - .../replaceContains/functionLiteralArgumentInExpression.kt | 1 - .../functionLiteralArgumentInExpression.kt.after | 1 - .../replaceContains/missingDefaultArgument.kt | 2 -- .../replaceContains/unacceptableVararg1.kt | 1 - 11 files changed, 4 insertions(+), 13 deletions(-) diff --git a/idea/idea-fir-fe10-binding/src/org/jetbrains/kotlin/idea/fir/fe10/binding/CallAndResolverCallWrappers.kt b/idea/idea-fir-fe10-binding/src/org/jetbrains/kotlin/idea/fir/fe10/binding/CallAndResolverCallWrappers.kt index 60fcb697c58..f704c9667e8 100644 --- a/idea/idea-fir-fe10-binding/src/org/jetbrains/kotlin/idea/fir/fe10/binding/CallAndResolverCallWrappers.kt +++ b/idea/idea-fir-fe10-binding/src/org/jetbrains/kotlin/idea/fir/fe10/binding/CallAndResolverCallWrappers.kt @@ -167,15 +167,17 @@ internal class FirWrapperResolvedCall(val firSimpleWrapperCall: FirSimpleWrapper val firArguments = firCall.withFir { it.argumentMapping } ?: context.implementationPostponed() val argumentExpression = valueArgument.getArgumentExpression() ?: context.implementationPostponed() + fun FirExpression.isMyArgument() = realPsi === valueArgument || realPsi === argumentExpression + var targetFirParameter: FirValueParameter? = null outer@ for ((firExpression, firValueParameter) in firArguments.entries) { if (firExpression is FirVarargArgumentsExpression) { for (subExpression in firExpression.arguments) - if (subExpression.realPsi === argumentExpression) { + if (subExpression.isMyArgument()) { targetFirParameter = firValueParameter break@outer } - } else if (firExpression.realPsi === argumentExpression) { + } else if (firExpression.isMyArgument()) { targetFirParameter = firValueParameter break@outer } diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt index a11a7f575f7..5b7199bdfd6 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(fn: () -> Boolean) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt.after b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt.after index 9fabbf324d3..984e5ca80a8 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt.after +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgument.kt.after @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(fn: () -> Boolean) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt index 904b55bcd32..369b0319d99 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(fn: () -> Boolean) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt.after b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt.after index 9fabbf324d3..984e5ca80a8 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt.after +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAfterSemicolon.kt.after @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(fn: () -> Boolean) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt index dd895c4356e..a982aaaa0de 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(fn: () -> Boolean) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt.after b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt.after index 7671be8acde..7f22728f2a2 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt.after +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentAtStartOfBlock.kt.after @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(fn: () -> Boolean) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt index f821faf3821..4eec907d0e2 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun doSomething(a: T) {} fun test() { diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt.after b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt.after index 1107bf636e6..c63d0cc5bb6 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt.after +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/functionLiteralArgumentInExpression.kt.after @@ -1,4 +1,3 @@ -// IGNORE_FE10_BINDING_BY_FIR fun doSomething(a: T) {} fun test() { diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/missingDefaultArgument.kt b/idea/testData/intentions/conventionNameCalls/replaceContains/missingDefaultArgument.kt index 4abc5e9a0c5..e84417350ea 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/missingDefaultArgument.kt +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/missingDefaultArgument.kt @@ -1,7 +1,5 @@ // IS_APPLICABLE: false // ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter -// IGNORE_FE10_BINDING_BY_FIR - fun test() { class Test{ operator fun contains(a: Int=1, b: Int=2) : Boolean = true diff --git a/idea/testData/intentions/conventionNameCalls/replaceContains/unacceptableVararg1.kt b/idea/testData/intentions/conventionNameCalls/replaceContains/unacceptableVararg1.kt index 60b352a0748..851a73a6693 100644 --- a/idea/testData/intentions/conventionNameCalls/replaceContains/unacceptableVararg1.kt +++ b/idea/testData/intentions/conventionNameCalls/replaceContains/unacceptableVararg1.kt @@ -1,6 +1,5 @@ // IS_APPLICABLE: false // ERROR: 'operator' modifier is inapplicable on this function: must have a single value parameter -// IGNORE_FE10_BINDING_BY_FIR fun test() { class Test{ operator fun contains(vararg b: Int, c: Int = 0): Boolean = true