PSI Unifier: Use convention-based call for array access expressions when comparing elements by resolved calls
#KT-8312 Fixed
This commit is contained in:
@@ -306,11 +306,16 @@ public class JetPsiUnifier(
|
||||
private val JetElement.bindingContext: BindingContext get() = if (this in originalPattern) patternContext else targetContext
|
||||
|
||||
private fun JetElement.getAdjustedResolvedCall(): ResolvedCall<*>? {
|
||||
val rc = getResolvedCall(bindingContext)?.let {
|
||||
when {
|
||||
it !is VariableAsFunctionResolvedCall -> it
|
||||
this is JetSimpleNameExpression -> it.variableCall
|
||||
else -> it.functionCall
|
||||
val rc = if (this is JetArrayAccessExpression) {
|
||||
bindingContext[BindingContext.INDEXED_LVALUE_GET, this]
|
||||
}
|
||||
else {
|
||||
getResolvedCall(bindingContext)?.let {
|
||||
when {
|
||||
it !is VariableAsFunctionResolvedCall -> it
|
||||
this is JetSimpleNameExpression -> it.variableCall
|
||||
else -> it.functionCall
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun fn(index : Int, list: List<()->Unit>) {
|
||||
when {
|
||||
index in list.indices -> <selection>list[index]</selection>()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// WITH_RUNTIME
|
||||
|
||||
fun fn(index : Int, list: List<()->Unit>) {
|
||||
when {
|
||||
index in list.indices -> {
|
||||
val function = list[index]
|
||||
function()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
fun test(index: Int, array: Array<() -> Unit>) {
|
||||
val a = <selection>array[index]</selection>()
|
||||
val b = array[index]
|
||||
val c = array.get(index)
|
||||
val d = array.get(index).invoke()
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
array[index]
|
||||
|
||||
array[index]
|
||||
|
||||
array.get(index)
|
||||
|
||||
array.get(index)
|
||||
+6
@@ -61,6 +61,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doIntroduceVariableTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ComplexCallee.kt")
|
||||
public void testComplexCallee() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/ComplexCallee.kt");
|
||||
doIntroduceVariableTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ConstructorDelegationCall.kt")
|
||||
public void testConstructorDelegationCall() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/ConstructorDelegationCall.kt");
|
||||
|
||||
@@ -389,6 +389,12 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callAndCalleeRuntime.kt")
|
||||
public void testCallAndCalleeRuntime() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/calls/callAndCalleeRuntime.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callTypeArgumentsRuntime.kt")
|
||||
public void testCallTypeArgumentsRuntime() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/calls/callTypeArgumentsRuntime.kt");
|
||||
|
||||
Reference in New Issue
Block a user