[FIR] Fix callable references to fields / parameters / etc.
Before this commit, only references to functions & properties were possible, now fields & parameters are also supported
This commit is contained in:
@@ -194,7 +194,7 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() {
|
||||
|
||||
val resultingType: ConeKotlinType = when (fir) {
|
||||
is FirFunction -> createKFunctionType(fir, resultingReceiverType, returnTypeRef)
|
||||
is FirProperty -> createKPropertyType(fir, resultingReceiverType, returnTypeRef)
|
||||
is FirVariable<*> -> createKPropertyType(fir, resultingReceiverType, returnTypeRef)
|
||||
else -> ConeKotlinErrorType("Unknown callable kind: ${fir::class}")
|
||||
}.let(candidate.substitutor::substituteOrSelf)
|
||||
|
||||
@@ -234,13 +234,13 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() {
|
||||
}
|
||||
|
||||
private fun createKPropertyType(
|
||||
property: FirProperty,
|
||||
propertyOrField: FirVariable<*>,
|
||||
receiverType: ConeKotlinType?,
|
||||
returnTypeRef: FirResolvedTypeRef
|
||||
): ConeKotlinType {
|
||||
val propertyType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for of $property")
|
||||
val propertyType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for of $propertyOrField")
|
||||
return createKPropertyType(
|
||||
receiverType, propertyType, isMutable = property.isVar
|
||||
receiverType, propertyType, isMutable = propertyOrField.isVar
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// FILE: JavaClass.java
|
||||
|
||||
public class JavaClass {
|
||||
public static String staticField;
|
||||
public String nonStaticField;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
fun test() {
|
||||
val staticReference = JavaClass::staticField
|
||||
val nonStaticReference = JavaClass::nonStaticField
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
FILE: test.kt
|
||||
public final fun test(): R|kotlin/Unit| {
|
||||
lval staticReference: R|kotlin/reflect/KMutableProperty1<JavaClass, ft<kotlin/String, kotlin/String?>!>| = Q|JavaClass|::R|/JavaClass.staticField|
|
||||
lval nonStaticReference: R|kotlin/reflect/KMutableProperty1<JavaClass, ft<kotlin/String, kotlin/String?>!>| = Q|JavaClass|::R|/JavaClass.nonStaticField|
|
||||
}
|
||||
+5
@@ -504,6 +504,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/innerQualifier.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaFieldCallable.kt")
|
||||
public void testJavaFieldCallable() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambda.kt")
|
||||
public void testLambda() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/lambda.kt");
|
||||
|
||||
Generated
+5
@@ -504,6 +504,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/innerQualifier.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaFieldCallable.kt")
|
||||
public void testJavaFieldCallable() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("lambda.kt")
|
||||
public void testLambda() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/expresssions/lambda.kt");
|
||||
|
||||
Reference in New Issue
Block a user