PSI Pattern Matching: Respect type arguments when matching calls
#KT-6496 Fixed
This commit is contained in:
@@ -276,12 +276,30 @@ public class JetPsiUnifier(
|
||||
}
|
||||
}
|
||||
|
||||
fun checkTypeArguments(): Status? {
|
||||
val typeArgs1 = rc1.getTypeArguments().toList()
|
||||
val typeArgs2 = rc2.getTypeArguments().toList()
|
||||
if (typeArgs1.size() != typeArgs2.size()) return UNMATCHED
|
||||
|
||||
for ((typeArg1, typeArg2) in (typeArgs1 zip typeArgs2)) {
|
||||
if (!matchDescriptors(typeArg1.first, typeArg2.first)) return UNMATCHED
|
||||
|
||||
val s = matchTypes(typeArg1.second, typeArg2.second)
|
||||
if (s != MATCHED) return s
|
||||
}
|
||||
|
||||
return MATCHED
|
||||
}
|
||||
|
||||
return when {
|
||||
!checkSpecialOperations() -> UNMATCHED
|
||||
!matchDescriptors(rc1.getCandidateDescriptor(), rc2.getCandidateDescriptor()) -> UNMATCHED
|
||||
!checkReceivers() -> UNMATCHED
|
||||
rc1.isSafeCall() != rc2.isSafeCall() -> UNMATCHED
|
||||
else -> checkArguments()
|
||||
else -> {
|
||||
val s = checkTypeArguments()
|
||||
if (s != MATCHED) s else checkArguments()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -337,6 +355,7 @@ public class JetPsiUnifier(
|
||||
|
||||
private fun matchTypes(type1: JetType?, type2: JetType?): Status? {
|
||||
if (type1 != null && type2 != null) {
|
||||
if (type1.isError() || type2.isError()) return null
|
||||
if (TypeUtils.equalTypes(type1, type2)) return MATCHED
|
||||
|
||||
if (type1.isMarkedNullable() != type2.isMarkedNullable()) return UNMATCHED
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(c : Collection<String>){
|
||||
c.filterTo(ArrayList<String>())<selection>{ it.length() > 1 }</selection>
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// WITH_RUNTIME
|
||||
fun foo(c : Collection<String>){
|
||||
val function: (String) -> Boolean = { it.length() > 1 }
|
||||
c.filterTo(ArrayList<String>(), function)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// DISABLE-ERRORS
|
||||
class A
|
||||
class B
|
||||
|
||||
fun foo<T>(klass: Class<T>) {
|
||||
|
||||
}
|
||||
|
||||
fun bar<T>(klass: Class<T>) {
|
||||
|
||||
}
|
||||
|
||||
fun main() {
|
||||
foo(<selection>javaClass<A>()</selection>)
|
||||
foo(javaClass<B>())
|
||||
bar(javaClass<B>())
|
||||
bar(javaClass<A>())
|
||||
javaClass()
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
javaClass<A>()
|
||||
|
||||
javaClass<A>()
|
||||
+6
@@ -93,6 +93,12 @@ public class JetExtractionTestGenerated extends AbstractJetExtractionTest {
|
||||
doIntroduceVariableTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FunctionLiteralWithExtraArgs.kt")
|
||||
public void testFunctionLiteralWithExtraArgs() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/FunctionLiteralWithExtraArgs.kt");
|
||||
doIntroduceVariableTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("IfCondition.kt")
|
||||
public void testIfCondition() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/refactoring/introduceVariable/IfCondition.kt");
|
||||
|
||||
@@ -396,6 +396,12 @@ public class JetPsiUnifierTestGenerated extends AbstractJetPsiUnifierTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callTypeArgumentsRuntime.kt")
|
||||
public void testCallTypeArgumentsRuntime() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/calls/callTypeArgumentsRuntime.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("externalArgumentsRuntime.kt")
|
||||
public void testExternalArgumentsRuntime() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/unifier/equivalence/expressions/calls/externalArgumentsRuntime.kt");
|
||||
|
||||
Reference in New Issue
Block a user