From beeb0f10988294e989163fd149447d0e5d9fa804 Mon Sep 17 00:00:00 2001 From: "Victoria.Petrakovich" Date: Tue, 26 Mar 2024 20:16:03 +0000 Subject: [PATCH] [kotlin] UsePropertyAccessSyntaxInspection: Get receiver types correctly for callable references on constructors For example, Foo()::getFoo ^KTIJ-29118 Fixed Merge-request: IJ-MR-130070 Merged-by: Victoria Petrakovich GitOrigin-RevId: 043bbaae95e30f22963db8dcf4c8c7ee06098aa6 --- .../inspections/UsePropertyAccessSyntaxInspection.kt | 5 ++++- .../replaceCallableReferenceCalledOnConstructor.kt | 3 +-- .../replaceCallableReferenceCalledOnConstructor.kt.after | 3 +-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt index aa222a19b363..ee3ef0c3360c 100644 --- a/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt +++ b/plugins/kotlin/code-insight/inspections-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/inspections/UsePropertyAccessSyntaxInspection.kt @@ -117,7 +117,10 @@ class UsePropertyAccessSyntaxInspection : LocalInspectionTool(), CleanupLocalIns val problemHighlightType = getProblemHighlightType(symbolPsi) - val receiverType = callableReferenceExpression.getReceiverKtType()?.lowerBoundIfFlexible() ?: return + val receiverType = + callableReferenceExpression.resolveCall() + ?.successfulFunctionCallOrNull()?.partiallyAppliedSymbol?.dispatchReceiver?.type?.lowerBoundIfFlexible() + ?: callableReferenceExpression.getReceiverKtType()?.lowerBoundIfFlexible() ?: return val syntheticProperty = getSyntheticProperty(propertyNames, receiverType) ?: return diff --git a/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt b/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt index 9d6a946fbe43..a7be5a2be929 100644 --- a/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt +++ b/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt @@ -1,8 +1,7 @@ // LANGUAGE_VERSION: 2.1 // COMPILER_ARGUMENTS: -XXLanguage:+ReferencesToSyntheticJavaProperties // FIX: Use property access syntax -// IGNORE_K2 -// Delete the ignore directive after fixing KTIJ-29118 + fun main() { suppressUnused(Foo()::getFoo) } diff --git a/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt.after b/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt.after index b43139f93cbc..d3d9112fb400 100644 --- a/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt.after +++ b/plugins/kotlin/idea/tests/testData/inspectionsLocal/usePropertyAccessSyntax/callableReferenceExpressions/replaceCallableReferenceCalledOnConstructor.kt.after @@ -1,8 +1,7 @@ // LANGUAGE_VERSION: 2.1 // COMPILER_ARGUMENTS: -XXLanguage:+ReferencesToSyntheticJavaProperties // FIX: Use property access syntax -// IGNORE_K2 -// Delete the ignore directive after fixing KTIJ-29118 + fun main() { suppressUnused(Foo()::foo) }