KTIJ-26752 [kotlin] Check if KtInvokeFunctionReference is resolved by resolveToCall instead of resolveToSymbols

For invoke operators coming from builtin functional types,
`resolveToSymbols` will return an empty list, and it seems like
an intentional design.
We have to deal with this for now.

GitOrigin-RevId: a81a82cdf3399f8c24edc4aeac0e4c4c61fe402b
This commit is contained in:
Roman Golyshev
2024-08-02 13:11:55 +02:00
committed by intellij-monorepo-bot
parent 2b8ca408ab
commit ff820ed565
8 changed files with 39 additions and 0 deletions

View File

@@ -47,6 +47,14 @@ internal class UsedReference private constructor(val reference: KtReference) {
get() = reference.resolvesByNames
fun KaSession.isResolved(): Boolean {
if (reference is KtInvokeFunctionReference) {
// invoke references on Kotlin builtin functional types (like `() -> Unit`)
// always have empty `resolveToSymbols`, so we have to do the check another way
val callInfo = reference.element.resolveToCall() ?: return false
return callInfo.calls.isNotEmpty()
}
val resolvedSymbols = reference.resolveToSymbols()
return resolvedSymbols.isNotEmpty()

View File

@@ -669,6 +669,11 @@ public abstract class FirJvmOptimizeImportsTestGenerated extends AbstractFirJvmO
runTest("../../idea/tests/testData/editor/optimizeImports/common/InvokeFunctionCallWithOverloadAmbiguity_literalReceiver.kt");
}
@TestMetadata("InvokeOnFunctionalTypeVsUnusedInvokeImport.kt")
public void testInvokeOnFunctionalTypeVsUnusedInvokeImport() throws Exception {
runTest("../../idea/tests/testData/editor/optimizeImports/common/InvokeOnFunctionalTypeVsUnusedInvokeImport.kt");
}
@TestMetadata("IteratorFunction.kt")
public void testIteratorFunction() throws Exception {
runTest("../../idea/tests/testData/editor/optimizeImports/common/IteratorFunction.kt");

View File

@@ -406,6 +406,11 @@ public abstract class JsOptimizeImportsTestGenerated extends AbstractJsOptimizeI
runTest("testData/editor/optimizeImports/common/InvokeFunctionCallWithOverloadAmbiguity_literalReceiver.kt");
}
@TestMetadata("InvokeOnFunctionalTypeVsUnusedInvokeImport.kt")
public void testInvokeOnFunctionalTypeVsUnusedInvokeImport() throws Exception {
runTest("testData/editor/optimizeImports/common/InvokeOnFunctionalTypeVsUnusedInvokeImport.kt");
}
@TestMetadata("IteratorFunction.kt")
public void testIteratorFunction() throws Exception {
runTest("testData/editor/optimizeImports/common/IteratorFunction.kt");

View File

@@ -674,6 +674,11 @@ public abstract class JvmOptimizeImportsTestGenerated extends AbstractJvmOptimiz
runTest("testData/editor/optimizeImports/common/InvokeFunctionCallWithOverloadAmbiguity_literalReceiver.kt");
}
@TestMetadata("InvokeOnFunctionalTypeVsUnusedInvokeImport.kt")
public void testInvokeOnFunctionalTypeVsUnusedInvokeImport() throws Exception {
runTest("testData/editor/optimizeImports/common/InvokeOnFunctionalTypeVsUnusedInvokeImport.kt");
}
@TestMetadata("IteratorFunction.kt")
public void testIteratorFunction() throws Exception {
runTest("testData/editor/optimizeImports/common/IteratorFunction.kt");

View File

@@ -0,0 +1,7 @@
package test
import dependency.invoke
fun test(action: () -> Unit) {
action()
}

View File

@@ -0,0 +1,5 @@
package test
fun test(action: () -> Unit) {
action()
}

View File

@@ -0,0 +1 @@
Additional checking of reference KtInvokeFunctionReference: action()