diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 3559698d658..b519bcd6a47 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -228,10 +228,11 @@ fun createFunctionalType( fun createKPropertyType( receiverType: ConeKotlinType?, - rawReturnType: ConeKotlinType + rawReturnType: ConeKotlinType, + isMutable: Boolean ): ConeLookupTagBasedType { val arguments = if (receiverType != null) listOf(receiverType, rawReturnType) else listOf(rawReturnType) - val classId = StandardClassIds.reflectByName("KProperty${arguments.size - 1}") + val classId = StandardClassIds.reflectByName("K${if (isMutable) "Mutable" else ""}Property${arguments.size - 1}") return ConeClassTypeImpl(ConeClassLikeLookupTagImpl(classId), arguments.toTypedArray(), isNullable = false) } 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 bf3223b4791..0f264623c26 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 @@ -237,7 +237,7 @@ private fun createKPropertyType( ): ConeKotlinType { val propertyType = returnTypeRef.coneTypeSafe() ?: ConeKotlinErrorType("No type for of $property") return createKPropertyType( - receiverType, propertyType + receiverType, propertyType, isMutable = property.isVar ) } diff --git a/compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.kt b/compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.kt new file mode 100644 index 00000000000..8f1dbee9c03 --- /dev/null +++ b/compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.kt @@ -0,0 +1,16 @@ +import kotlin.reflect.KMutableProperty0 +import kotlin.reflect.KMutableProperty1 + +class A { + var bar: Int = 1 +} + +var bar = 1 + +fun foo1(x: KMutableProperty0) {} +fun foo2(x: KMutableProperty1) {} + +fun main() { + foo1(::bar) + foo2(A::bar) +} diff --git a/compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.txt b/compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.txt new file mode 100644 index 00000000000..c8e22656b56 --- /dev/null +++ b/compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.txt @@ -0,0 +1,22 @@ +FILE: varProperties.kt + public final class A : R|kotlin/Any| { + public constructor(): R|A| { + super() + } + + public final var bar: R|kotlin/Int| = Int(1) + public get(): R|kotlin/Int| + public set(value: R|kotlin/Int|): R|kotlin/Unit| + + } + public final var bar: R|kotlin/Int| = Int(1) + public get(): R|kotlin/Int| + public set(value: R|kotlin/Int|): R|kotlin/Unit| + public final fun foo1(x: R|kotlin/reflect/KMutableProperty0|): R|kotlin/Unit| { + } + public final fun foo2(x: R|kotlin/reflect/KMutableProperty1|): R|kotlin/Unit| { + } + public final fun main(): R|kotlin/Unit| { + R|/foo1|(::R|/bar|) + R|/foo2|(Q|A|::R|/A.bar|) + } 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 50f4c49db02..566e10fe55a 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -135,6 +135,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/diagnostics/callableReferences/simpleNoReceiver.kt"); } + @TestMetadata("varProperties.kt") + public void testVarProperties() throws Exception { + runTest("compiler/fir/resolve/testData/diagnostics/callableReferences/varProperties.kt"); + } + @TestMetadata("compiler/fir/resolve/testData/diagnostics/callableReferences/fromBasicDiagnosticTests") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)