diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt index 20b22131f6f..9e516d95f0a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/LocalVariableResolver.kt @@ -20,9 +20,7 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations -import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor -import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl -import org.jetbrains.kotlin.descriptors.impl.VariableDescriptorWithInitializerImpl +import org.jetbrains.kotlin.descriptors.impl.* import org.jetbrains.kotlin.diagnostics.Errors.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.KtProperty @@ -86,6 +84,8 @@ class LocalVariableResolver( delegateExpression, typingContext.scope, typingContext.trace) + propertyDescriptor.getter?.updateAccessorFlagsFromResolvedCallForDelegatedProperty(typingContext.trace) + propertyDescriptor.setter?.updateAccessorFlagsFromResolvedCallForDelegatedProperty(typingContext.trace) } } @@ -212,4 +212,13 @@ class LocalVariableResolver( trace.record(BindingContext.VARIABLE, variable, variableDescriptor) return variableDescriptor } + + private fun VariableAccessorDescriptor.updateAccessorFlagsFromResolvedCallForDelegatedProperty(trace: BindingTrace) { + if (this is FunctionDescriptorImpl) { + val resultingDescriptor = trace.bindingContext.get(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, this)?.resultingDescriptor + if (resultingDescriptor != null) { + setSuspend(resultingDescriptor.isSuspend) + } + } + } } diff --git a/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.kt b/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.kt new file mode 100644 index 00000000000..5a8f387e6f7 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.kt @@ -0,0 +1,27 @@ +// WITH_RUNTIME + +import kotlin.coroutines.experimental.intrinsics.COROUTINE_SUSPENDED +import kotlin.coroutines.experimental.intrinsics.suspendCoroutineOrReturn +import kotlin.reflect.KProperty + +class A { + var z: Int = 42 + + operator suspend fun getValue(thisRef: Any?, property: KProperty<*>) = z + + operator suspend fun setValue(thisRef: Any?, property: KProperty<*>, value: Int): Unit = suspendCoroutineOrReturn { x -> + z = value + x.resume(Unit) + COROUTINE_SUSPENDED + } + + operator suspend fun provideDelegate(host: Any?, p: Any): A = suspendCoroutineOrReturn { x -> + x.resume(this) + COROUTINE_SUSPENDED + } +} + +suspend fun test() { + val testVal by A() + var testVar by A() +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.txt b/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.txt new file mode 100644 index 00000000000..3c95b149667 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.txt @@ -0,0 +1,93 @@ +FILE /localDelegatedPropertyWithSuspendOperators.kt + CLASS CLASS A + CONSTRUCTOR public constructor A() + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' + INSTANCE_INITIALIZER_CALL classDescriptor='A' + PROPERTY public final var z: kotlin.Int + FIELD PROPERTY_BACKING_FIELD public final var z: kotlin.Int + EXPRESSION_BODY + CONST Int type=kotlin.Int value='42' + FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + GET_FIELD 'z: Int' type=kotlin.Int origin=null + receiver: GET_VAR '' type=A origin=null + FUN DEFAULT_PROPERTY_ACCESSOR public final fun (: kotlin.Int): kotlin.Unit + BLOCK_BODY + SET_FIELD 'z: Int' type=kotlin.Unit origin=null + receiver: GET_VAR '' type=A origin=null + value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null + FUN public final operator suspend fun getValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='getValue(Any?, KProperty<*>): Int' + CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY + $this: GET_VAR '' type=A origin=null + FUN public final operator suspend fun setValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>, value: kotlin.Int): kotlin.Unit + BLOCK_BODY + RETURN type=kotlin.Nothing from='setValue(Any?, KProperty<*>, Int): Unit' + CALL 'suspendCoroutineOrReturn(crossinline (Continuation) -> Any?): Unit' type=kotlin.Unit origin=null + : Unit + block: BLOCK type=(kotlin.coroutines.experimental.Continuation) -> kotlin.Any origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun (x: kotlin.coroutines.experimental.Continuation): kotlin.Any + BLOCK_BODY + CALL '(Int): Unit' type=kotlin.Unit origin=EQ + $this: GET_VAR '' type=A origin=null + : GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null + CALL 'resume(Unit): Unit' type=kotlin.Unit origin=null + $this: GET_VAR 'value-parameter x: Continuation' type=kotlin.coroutines.experimental.Continuation origin=null + value: GET_OBJECT 'Unit' type=kotlin.Unit + RETURN type=kotlin.Nothing from='(Continuation): Any' + CALL '(): Any' type=kotlin.Any origin=GET_PROPERTY + CALLABLE_REFERENCE '(Continuation): Any' type=(kotlin.coroutines.experimental.Continuation) -> kotlin.Any origin=LAMBDA + FUN public final operator suspend fun provideDelegate(host: kotlin.Any?, p: kotlin.Any): A + BLOCK_BODY + RETURN type=kotlin.Nothing from='provideDelegate(Any?, Any): A' + CALL 'suspendCoroutineOrReturn(crossinline (Continuation) -> Any?): A' type=A origin=null + : A + block: BLOCK type=(kotlin.coroutines.experimental.Continuation) -> kotlin.Any origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA local final fun (x: kotlin.coroutines.experimental.Continuation): kotlin.Any + BLOCK_BODY + CALL 'resume(A): Unit' type=kotlin.Unit origin=null + $this: GET_VAR 'value-parameter x: Continuation' type=kotlin.coroutines.experimental.Continuation origin=null + value: GET_VAR '' type=A origin=null + RETURN type=kotlin.Nothing from='(Continuation): Any' + CALL '(): Any' type=kotlin.Any origin=GET_PROPERTY + CALLABLE_REFERENCE '(Continuation): Any' type=(kotlin.coroutines.experimental.Continuation) -> kotlin.Any origin=LAMBDA + FUN public suspend fun test(): kotlin.Unit + BLOCK_BODY + LOCAL_DELEGATED_PROPERTY val testVal: kotlin.Int + VAR DELEGATE val `testVal$delegate`: A + CALL 'provideDelegate(Any?, Any): A' type=A origin=null + $this: CALL 'constructor A()' type=A origin=null + host: CONST Null type=kotlin.Nothing? value='null' + p: CALLABLE_REFERENCE 'testVal: Int' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + FUN DELEGATED_PROPERTY_ACCESSOR local final suspend fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CALL 'getValue(Any?, KProperty<*>): Int' type=kotlin.Int origin=null + $this: GET_VAR '`testVal$delegate`: A' type=A origin=null + thisRef: CONST Null type=kotlin.Nothing? value='null' + property: CALLABLE_REFERENCE 'testVal: Int' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + LOCAL_DELEGATED_PROPERTY var testVar: kotlin.Int + VAR DELEGATE val `testVar$delegate`: A + CALL 'provideDelegate(Any?, Any): A' type=A origin=null + $this: CALL 'constructor A()' type=A origin=null + host: CONST Null type=kotlin.Nothing? value='null' + p: CALLABLE_REFERENCE 'testVar: Int' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + FUN DELEGATED_PROPERTY_ACCESSOR local final suspend fun (): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(): Int' + CALL 'getValue(Any?, KProperty<*>): Int' type=kotlin.Int origin=null + $this: GET_VAR '`testVar$delegate`: A' type=A origin=null + thisRef: CONST Null type=kotlin.Nothing? value='null' + property: CALLABLE_REFERENCE 'testVar: Int' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + FUN DELEGATED_PROPERTY_ACCESSOR local final suspend fun (value: kotlin.Int): kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='(Int): Int' + TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int + CALL 'setValue(Any?, KProperty<*>, Int): Unit' type=kotlin.Unit origin=null + $this: GET_VAR '`testVar$delegate`: A' type=A origin=null + thisRef: CONST Null type=kotlin.Nothing? value='null' + property: CALLABLE_REFERENCE 'testVar: Int' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + value: GET_VAR 'value-parameter value: Int' type=kotlin.Int origin=null diff --git a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java index c4c039c2590..8fbb3ad3712 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/ir/IrTextTestCaseGenerated.java @@ -257,6 +257,12 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase { doTest(fileName); } + @TestMetadata("localDelegatedPropertyWithSuspendOperators.kt") + public void testLocalDelegatedPropertyWithSuspendOperators() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/localDelegatedPropertyWithSuspendOperators.kt"); + doTest(fileName); + } + @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/ir/irText/declarations/packageLevelProperties.kt");