AA: use explicit qualifier type if available

...when computing receiver type for double colon expression

^KT-65150 fixed
This commit is contained in:
Jinseong Jeon
2024-01-19 14:28:32 -08:00
committed by Space Team
parent 2277c1ba97
commit 2429d09edd
7 changed files with 53 additions and 6 deletions
@@ -64,6 +64,12 @@ public class Fe10IdeNormalAnalysisSourceModuleDoubleColonReceiverTypeTestGenerat
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/getClass_variable.kt");
}
@Test
@TestMetadata("methodReference_java.kt")
public void testMethodReference_java() throws Exception {
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/methodReference_java.kt");
}
@Test
@TestMetadata("methodReference_type.kt")
public void testMethodReference_type() throws Exception {
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.analysis.api.fir.components
import org.jetbrains.kotlin.analysis.api.components.KtBuiltinTypes
import org.jetbrains.kotlin.analysis.api.components.KtTypeProvider
import org.jetbrains.kotlin.analysis.api.components.buildClassType
import org.jetbrains.kotlin.analysis.api.fir.KtFirAnalysisSession
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirNamedClassOrObjectSymbol
import org.jetbrains.kotlin.analysis.api.fir.symbols.KtFirSymbol
@@ -34,10 +35,7 @@ import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
import org.jetbrains.kotlin.fir.declarations.FirProperty
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
import org.jetbrains.kotlin.fir.declarations.fullyExpandedClass
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.java.enhancement.EnhancedForWarningConeSubstitutor
import org.jetbrains.kotlin.fir.psi
import org.jetbrains.kotlin.fir.renderer.FirRenderer
@@ -195,8 +193,16 @@ internal class KtFirTypeProvider(
}
is FirCallableReferenceAccess -> {
when (val explicitReceiver = fir.explicitReceiver) {
is FirPropertyAccessExpression -> explicitReceiver.resolvedType.asKtType()
else -> fir.resolvedType.getReceiverOfReflectionType()?.asKtType()
is FirPropertyAccessExpression -> {
explicitReceiver.resolvedType.asKtType()
}
is FirResolvedQualifier -> {
explicitReceiver.classId?.let { analysisSession.buildClassType(it) }
?: fir.resolvedType.getReceiverOfReflectionType()?.asKtType()
}
else -> {
fir.resolvedType.getReceiverOfReflectionType()?.asKtType()
}
}
}
else -> {
@@ -64,6 +64,12 @@ public class FirIdeDependentAnalysisSourceModuleDoubleColonReceiverTypeTestGener
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/getClass_variable.kt");
}
@Test
@TestMetadata("methodReference_java.kt")
public void testMethodReference_java() throws Exception {
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/methodReference_java.kt");
}
@Test
@TestMetadata("methodReference_type.kt")
public void testMethodReference_type() throws Exception {
@@ -64,6 +64,12 @@ public class FirIdeNormalAnalysisSourceModuleDoubleColonReceiverTypeTestGenerate
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/getClass_variable.kt");
}
@Test
@TestMetadata("methodReference_java.kt")
public void testMethodReference_java() throws Exception {
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/methodReference_java.kt");
}
@Test
@TestMetadata("methodReference_type.kt")
public void testMethodReference_type() throws Exception {
@@ -64,6 +64,12 @@ public class FirStandaloneNormalAnalysisSourceModuleDoubleColonReceiverTypeTestG
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/getClass_variable.kt");
}
@Test
@TestMetadata("methodReference_java.kt")
public void testMethodReference_java() throws Exception {
runTest("analysis/analysis-api/testData/components/typeInfoProvider/doubleColonReceiverType/methodReference_java.kt");
}
@Test
@TestMetadata("methodReference_type.kt")
public void testMethodReference_type() throws Exception {
@@ -0,0 +1,15 @@
// FILE: IntMath.java
package my.math;
public final class IntMath {
public static int factorial(int n) {
return 42;
}
}
// FILE: main.kt
import my.math.IntMath
fun test() = IntMath:<caret>:factorial
@@ -0,0 +1,2 @@
expression: IntMath::factorial
receiver:: type: my.math.IntMath