FIR: Support callable references to vars
^KT-32725 In Progress
This commit is contained in:
@@ -228,10 +228,11 @@ fun createFunctionalType(
|
|||||||
|
|
||||||
fun createKPropertyType(
|
fun createKPropertyType(
|
||||||
receiverType: ConeKotlinType?,
|
receiverType: ConeKotlinType?,
|
||||||
rawReturnType: ConeKotlinType
|
rawReturnType: ConeKotlinType,
|
||||||
|
isMutable: Boolean
|
||||||
): ConeLookupTagBasedType {
|
): ConeLookupTagBasedType {
|
||||||
val arguments = if (receiverType != null) listOf(receiverType, rawReturnType) else listOf(rawReturnType)
|
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)
|
return ConeClassTypeImpl(ConeClassLikeLookupTagImpl(classId), arguments.toTypedArray(), isNullable = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -237,7 +237,7 @@ private fun createKPropertyType(
|
|||||||
): ConeKotlinType {
|
): ConeKotlinType {
|
||||||
val propertyType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for of $property")
|
val propertyType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for of $property")
|
||||||
return createKPropertyType(
|
return createKPropertyType(
|
||||||
receiverType, propertyType
|
receiverType, propertyType, isMutable = property.isVar
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+16
@@ -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)
|
||||||
|
}
|
||||||
+22
@@ -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|)
|
||||||
|
}
|
||||||
+5
@@ -135,6 +135,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
|
|||||||
runTest("compiler/fir/resolve/testData/diagnostics/callableReferences/simpleNoReceiver.kt");
|
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")
|
@TestMetadata("compiler/fir/resolve/testData/diagnostics/callableReferences/fromBasicDiagnosticTests")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user