mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
KTIJ-33579 [kotlin] Use ImportContextWithFixedReceiverType in ComponentFunctionImportQuickFixFactory to properly handle destructuring in lambdas
^KTIJ-33579 Fixed GitOrigin-RevId: b3f921bba5ef097f1998692aed8fac2e99c303b5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
999141b959
commit
c5c7b01cd0
+15
-1
@@ -8,6 +8,7 @@ import org.jetbrains.kotlin.idea.base.analysis.api.utils.KtSymbolFromIndexProvid
|
||||
import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.imprt.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
|
||||
internal object ComponentFunctionImportQuickFixFactory : AbstractImportQuickFixFactory() {
|
||||
override fun KaSession.detectPositionContext(diagnostic: KaDiagnosticWithPsi<*>): ImportContext? =
|
||||
@@ -15,7 +16,20 @@ internal object ComponentFunctionImportQuickFixFactory : AbstractImportQuickFixF
|
||||
is KaFirDiagnostic.ComponentFunctionMissing,
|
||||
is KaFirDiagnostic.ComponentFunctionAmbiguity -> {
|
||||
val destructuredExpression = diagnostic.psi as? KtExpression ?: return null
|
||||
DefaultImportContext(destructuredExpression, ImportPositionTypeAndReceiver.OperatorCall(destructuredExpression))
|
||||
|
||||
val destructuredType = when (destructuredExpression) {
|
||||
// destructuring in lambda parameter position (e.g. `foo { (a, b) -> ... }`)
|
||||
is KtParameter -> destructuredExpression.returnType
|
||||
|
||||
// regular assignment destructuring (e.g. `val (a, b) = ...`)
|
||||
else -> destructuredExpression.expressionType
|
||||
} ?: return null
|
||||
|
||||
ImportContextWithFixedReceiverType(
|
||||
destructuredExpression,
|
||||
ImportPositionType.OperatorCall,
|
||||
explicitReceiverType = destructuredType,
|
||||
)
|
||||
}
|
||||
|
||||
else -> null
|
||||
|
||||
-2
@@ -1,7 +1,6 @@
|
||||
// FILE: first.before.kt
|
||||
// "Import operator 'Some.component1'" "true"
|
||||
// IGNORE_K1
|
||||
// IGNORE_K2
|
||||
|
||||
package testing
|
||||
|
||||
@@ -26,7 +25,6 @@ operator fun Some.component2() = 3
|
||||
// FILE: first.after.kt
|
||||
// "Import operator 'Some.component1'" "true"
|
||||
// IGNORE_K1
|
||||
// IGNORE_K2
|
||||
|
||||
package testing
|
||||
|
||||
|
||||
-2
@@ -1,7 +1,6 @@
|
||||
// FILE: first.before.kt
|
||||
// "Import operator 'Some.component2'" "true"
|
||||
// IGNORE_K1
|
||||
// IGNORE_K2
|
||||
|
||||
package testing
|
||||
|
||||
@@ -26,7 +25,6 @@ operator fun Some.component2() = 3
|
||||
// FILE: first.after.kt
|
||||
// "Import operator 'Some.component2'" "true"
|
||||
// IGNORE_K1
|
||||
// IGNORE_K2
|
||||
|
||||
package testing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user