diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt index 1ed909341dc..a680d8f5ea0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/ResolverParts.kt @@ -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() ?: ConeKotlinErrorType("No type for of $property") + val propertyType = returnTypeRef.coneTypeSafe() ?: ConeKotlinErrorType("No type for of $propertyOrField") return createKPropertyType( - receiverType, propertyType, isMutable = property.isVar + receiverType, propertyType, isMutable = propertyOrField.isVar ) } diff --git a/compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.kt b/compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.kt new file mode 100644 index 00000000000..5435fe4042c --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.kt @@ -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 +} \ No newline at end of file diff --git a/compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.txt b/compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.txt new file mode 100644 index 00000000000..c26af7d5396 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/expresssions/javaFieldCallable.txt @@ -0,0 +1,5 @@ +FILE: test.kt + public final fun test(): R|kotlin/Unit| { + lval staticReference: R|kotlin/reflect/KMutableProperty1!>| = Q|JavaClass|::R|/JavaClass.staticField| + lval nonStaticReference: R|kotlin/reflect/KMutableProperty1!>| = Q|JavaClass|::R|/JavaClass.nonStaticField| + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index f6d5da92ed4..1199a2fd184 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -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"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index fb9528f0a63..e2a2eba5938 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -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"); diff --git a/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt index 06eb08b4f3c..e749304016b 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/javaInstanceField.fir.kt @@ -17,10 +17,10 @@ public class JavaClass { import kotlin.reflect.* fun test() { - val pubFinRef: KProperty1 = JavaClass::publicFinal - val pubMutRef: KMutableProperty1 = JavaClass::publicMutable - val protFinRef: KProperty1 = JavaClass::protectedFinal - val protMutRef: KMutableProperty1 = JavaClass::protectedMutable + val pubFinRef: KProperty1 = JavaClass::publicFinal + val pubMutRef: KMutableProperty1 = JavaClass::publicMutable + val protFinRef: KProperty1 = JavaClass::protectedFinal + val protMutRef: KMutableProperty1 = JavaClass::protectedMutable val privFinRef: KProperty1 = JavaClass::privateFinal val privMutRef: KMutableProperty1 = JavaClass::privateMutable } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt index ee0f768f20a..ecc1e7ee486 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/javaStaticFieldViaImport.fir.kt @@ -19,10 +19,10 @@ import JavaClass.* import kotlin.reflect.* fun test() { - val pubFinRef: KProperty0 = ::publicFinal - val pubMutRef: KMutableProperty0 = ::publicMutable - val protFinRef: KProperty = ::protectedFinal - val protMutRef: KMutableProperty = ::protectedMutable + val pubFinRef: KProperty0 = ::publicFinal + val pubMutRef: KMutableProperty0 = ::publicMutable + val protFinRef: KProperty = ::protectedFinal + val protMutRef: KMutableProperty = ::protectedMutable val privFinRef: KProperty = ::privateFinal val privMutRef: KMutableProperty = ::privateMutable } diff --git a/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt b/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt index 09ca94be062..c170c78a97a 100644 --- a/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt +++ b/compiler/testData/diagnostics/tests/callableReference/property/localVariable.fir.kt @@ -3,7 +3,7 @@ fun eat(value: Any) {} fun test(param: String) { - val a = ::param + val a = ::param val local = "local" val b = ::local diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt index c8a90d300a7..f02c153f3c8 100644 --- a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloads.fir.kt @@ -22,6 +22,6 @@ fun main(c: CollectionWithSize) { CompressionType.ZIP.name checkType { _() } c.size checkType { _() } - CompressionType.ZIP::name checkType { _>() } - c::size checkType { _>() } + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } } diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt index 983d868b288..3321253e4a3 100644 --- a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsDisabled.fir.kt @@ -23,6 +23,6 @@ fun main(c: CollectionWithSize) { CompressionType.ZIP.name checkType { _() } c.size checkType { _() } - CompressionType.ZIP::name checkType { _>() } - c::size checkType { _>() } + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } } diff --git a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt index 36a05a378c7..0bb6d5b9bbe 100644 --- a/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/properties/fieldPropertyOverloadsNI.fir.kt @@ -22,6 +22,6 @@ fun main(c: CollectionWithSize) { CompressionType.ZIP.name checkType { _() } c.size checkType { _() } - CompressionType.ZIP::name checkType { _>() } - c::size checkType { _>() } + CompressionType.ZIP::name checkType { _>() } + c::size checkType { _>() } } diff --git a/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt b/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt index 7d40da4e59f..66db339b185 100644 --- a/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt +++ b/compiler/testData/ir/irText/expressions/propertyReferences.fir.txt @@ -250,23 +250,23 @@ FILE fqName: fileName:/propertyReferences.kt RETURN type=kotlin.Nothing from='public final fun (): kotlin.reflect.KProperty0 declared in ' GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_constVal type:kotlin.reflect.KProperty0 visibility:private [final,static]' type=kotlin.reflect.KProperty0 origin=null PROPERTY name:test_J_CONST visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test_J_CONST type:IrErrorType visibility:private [final,static] + FIELD PROPERTY_BACKING_FIELD name:test_J_CONST type:kotlin.reflect.KProperty1<.J, kotlin.Int> visibility:private [final,static] EXPRESSION_BODY - ERROR_CALL 'Unsupported callable reference: Q|J|::#' type=IrErrorType - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType + ERROR_CALL 'Unsupported callable reference: Q|J|::R|/J.CONST|' type=kotlin.reflect.KProperty1<.J, kotlin.Int> + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.reflect.KProperty1<.J, kotlin.Int> correspondingProperty: PROPERTY name:test_J_CONST visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_J_CONST type:IrErrorType visibility:private [final,static]' type=IrErrorType origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.reflect.KProperty1<.J, kotlin.Int> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_J_CONST type:kotlin.reflect.KProperty1<.J, kotlin.Int> visibility:private [final,static]' type=kotlin.reflect.KProperty1<.J, kotlin.Int> origin=null PROPERTY name:test_J_nonConst visibility:public modality:FINAL [val] - FIELD PROPERTY_BACKING_FIELD name:test_J_nonConst type:IrErrorType visibility:private [final,static] + FIELD PROPERTY_BACKING_FIELD name:test_J_nonConst type:kotlin.reflect.KMutableProperty1<.J, kotlin.Int> visibility:private [final,static] EXPRESSION_BODY - ERROR_CALL 'Unsupported callable reference: Q|J|::#' type=IrErrorType - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:IrErrorType + ERROR_CALL 'Unsupported callable reference: Q|J|::R|/J.nonConst|' type=kotlin.reflect.KMutableProperty1<.J, kotlin.Int> + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> () returnType:kotlin.reflect.KMutableProperty1<.J, kotlin.Int> correspondingProperty: PROPERTY name:test_J_nonConst visibility:public modality:FINAL [val] BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): IrErrorType declared in ' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_J_nonConst type:IrErrorType visibility:private [final,static]' type=IrErrorType origin=null + RETURN type=kotlin.Nothing from='public final fun (): kotlin.reflect.KMutableProperty1<.J, kotlin.Int> declared in ' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test_J_nonConst type:kotlin.reflect.KMutableProperty1<.J, kotlin.Int> visibility:private [final,static]' type=kotlin.reflect.KMutableProperty1<.J, kotlin.Int> origin=null PROPERTY name:test_varWithPrivateSet visibility:public modality:FINAL [val] FIELD PROPERTY_BACKING_FIELD name:test_varWithPrivateSet type:kotlin.reflect.KMutableProperty1<.C, kotlin.Int> visibility:private [final,static] EXPRESSION_BODY