FIR: implementation of delegateProvider in delegate resolve
This commit is contained in:
+15
-1
@@ -1063,6 +1063,20 @@ open class FirBodyResolveTransformer(
|
||||
}
|
||||
}
|
||||
|
||||
override fun transformWrappedDelegateExpression(
|
||||
wrappedDelegateExpression: FirWrappedDelegateExpression,
|
||||
data: Any?
|
||||
): CompositeTransformResult<FirStatement> {
|
||||
super.transformWrappedDelegateExpression(wrappedDelegateExpression, data)
|
||||
with(wrappedDelegateExpression) {
|
||||
val delegateProviderTypeRef = delegateProvider.typeRef
|
||||
val useDelegateProvider = delegateProviderTypeRef is FirResolvedTypeRef &&
|
||||
delegateProviderTypeRef !is FirErrorTypeRef &&
|
||||
delegateProviderTypeRef.type !is ConeKotlinErrorType
|
||||
return if (useDelegateProvider) delegateProvider.compose() else expression.compose()
|
||||
}
|
||||
}
|
||||
|
||||
override fun <F : FirVariable<F>> transformVariable(variable: FirVariable<F>, data: Any?): CompositeTransformResult<FirDeclaration> {
|
||||
variable.transformChildrenWithoutAccessors(this, variable.returnTypeRef)
|
||||
if (variable.initializer != null) {
|
||||
@@ -1100,7 +1114,7 @@ open class FirBodyResolveTransformer(
|
||||
}
|
||||
|
||||
override fun transformExpression(expression: FirExpression, data: Any?): CompositeTransformResult<FirStatement> {
|
||||
if (expression.resultType is FirImplicitTypeRef && expression !is FirWrappedArgumentExpression) {
|
||||
if (expression.resultType is FirImplicitTypeRef && expression !is FirWrappedExpression) {
|
||||
val type = FirErrorTypeRefImpl(session, expression.psi, "Type calculating for ${expression::class} is not supported")
|
||||
expression.resultType = type
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Delegate(val value: String) {
|
||||
operator fun getValue(thisRef: Any?, property: Any?) = value
|
||||
}
|
||||
|
||||
class DelegateProvider(val value: String) {
|
||||
operator fun provideDelegate(thisRef: Any?, property: Any?) = Delegate(value)
|
||||
}
|
||||
|
||||
val testTopLevel by DelegateProvider("OK")
|
||||
@@ -0,0 +1,31 @@
|
||||
FILE: simpleDelegateProvider.kt
|
||||
public final class Delegate : R|kotlin/Any| {
|
||||
public constructor(value: R|kotlin/String|): R|Delegate| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val value: R|kotlin/String| = R|<local>/value|
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final operator fun getValue(thisRef: R|kotlin/Any|?, property: R|kotlin/Any|?): R|kotlin/String| {
|
||||
^getValue R|/Delegate.value|
|
||||
}
|
||||
|
||||
}
|
||||
public final class DelegateProvider : R|kotlin/Any| {
|
||||
public constructor(value: R|kotlin/String|): R|DelegateProvider| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val value: R|kotlin/String| = R|<local>/value|
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final operator fun provideDelegate(thisRef: R|kotlin/Any|?, property: R|kotlin/Any|?): R|Delegate| {
|
||||
^provideDelegate R|/Delegate.Delegate|(R|/DelegateProvider.value|)
|
||||
}
|
||||
|
||||
}
|
||||
public final val testTopLevel: R|kotlin/String|by R|/DelegateProvider.DelegateProvider|(String(OK)).R|/DelegateProvider.provideDelegate|(Null(null), ::R|/testTopLevel|)
|
||||
public get(): R|kotlin/String| {
|
||||
^ D|/testTopLevel|.R|/Delegate.getValue|(Null(null), ::R|/testTopLevel|)
|
||||
}
|
||||
Generated
+5
@@ -94,6 +94,11 @@ public class FirResolveTestCaseWithStdlibGenerated extends AbstractFirResolveTes
|
||||
runTest("compiler/fir/resolve/testData/resolve/stdlib/reflectionClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleDelegateProvider.kt")
|
||||
public void testSimpleDelegateProvider() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/stdlib/simpleDelegateProvider.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleDelegatedToMap.kt")
|
||||
public void testSimpleDelegatedToMap() throws Exception {
|
||||
runTest("compiler/fir/resolve/testData/resolve/stdlib/simpleDelegatedToMap.kt");
|
||||
|
||||
Reference in New Issue
Block a user