FIR: Support callable references to vars

^KT-32725 In Progress
This commit is contained in:
Denis Zharkov
2019-10-25 16:15:57 +03:00
parent 4233cf1bd6
commit 9ac0ac50ea
5 changed files with 47 additions and 3 deletions
@@ -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)
}
@@ -237,7 +237,7 @@ private fun createKPropertyType(
): ConeKotlinType {
val propertyType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for of $property")
return createKPropertyType(
receiverType, propertyType
receiverType, propertyType, isMutable = property.isVar
)
}
@@ -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<Int>) {}
fun foo2(x: KMutableProperty1<A, Int>) {}
fun main() {
foo1(::bar)
foo2(A::bar)
}
@@ -0,0 +1,22 @@
FILE: varProperties.kt
public final class A : R|kotlin/Any| {
public constructor(): R|A| {
super<R|kotlin/Any|>()
}
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<kotlin/Int>|): R|kotlin/Unit| {
}
public final fun foo2(x: R|kotlin/reflect/KMutableProperty1<A, kotlin/Int>|): R|kotlin/Unit| {
}
public final fun main(): R|kotlin/Unit| {
R|/foo1|(::R|/bar|)
R|/foo2|(Q|A|::R|/A.bar|)
}
@@ -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)