diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendOperatorsCheckers.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendOperatorsCheckers.kt index d661953c3a0..6ccafb73066 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendOperatorsCheckers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/SuspendOperatorsCheckers.kt @@ -26,7 +26,8 @@ import org.jetbrains.kotlin.util.OperatorNameConventions object SuspendOperatorsCheckers : DeclarationChecker { private val UNSUPPORTED_OPERATOR_NAMES = setOf( OperatorNameConventions.CONTAINS, - OperatorNameConventions.GET, OperatorNameConventions.SET + OperatorNameConventions.GET, OperatorNameConventions.SET, + OperatorNameConventions.PROVIDE_DELEGATE, OperatorNameConventions.GET_VALUE, OperatorNameConventions.SET_VALUE ) override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { diff --git a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt index 22765622672..529c139ef5c 100644 --- a/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt +++ b/compiler/testData/codegen/box/coroutines/suspendFunctionAsCoroutine/operators.kt @@ -18,19 +18,20 @@ class A(val x: String) { var isMinusAssignCalled = false var isIncCalled = false operator suspend fun component1() = suspendThere(x + "K") - operator suspend fun getValue(thisRef: Any?, property: KProperty<*>) = suspendThere(x + "K") - operator suspend fun setValue(thisRef: Any?, property: KProperty<*>, value: String): Unit = suspendCoroutineUninterceptedOrReturn { x -> - if (value != "56") return@suspendCoroutineUninterceptedOrReturn Unit - isSetValueCalled = true - x.resume(Unit) - COROUTINE_SUSPENDED - } - - operator suspend fun provideDelegate(host: Any?, p: Any): A = suspendCoroutineUninterceptedOrReturn { x -> - isProvideDelegateCalled = true - x.resume(this) - COROUTINE_SUSPENDED - } + // There is no reason to support these operators until suspend properties are supported +// operator suspend fun getValue(thisRef: Any?, property: KProperty<*>) = suspendThere(x + "K") +// operator suspend fun setValue(thisRef: Any?, property: KProperty<*>, value: String): Unit = suspendCoroutineUninterceptedOrReturn { x -> +// if (value != "56") return@suspendCoroutineUninterceptedOrReturn Unit +// isSetValueCalled = true +// x.resume(Unit) +// COROUTINE_SUSPENDED +// } +// +// operator suspend fun provideDelegate(host: Any?, p: Any): A = suspendCoroutineUninterceptedOrReturn { x -> +// isProvideDelegateCalled = true +// x.resume(this) +// COROUTINE_SUSPENDED +// } operator suspend fun plus(y: String) = suspendThere(x + y) operator suspend fun unaryPlus() = suspendThere(x + "K") @@ -65,15 +66,15 @@ fun builder(c: suspend () -> Unit) { var a = A("O") -suspend fun foo1() { - var x by a - - if (x != "OK") throw RuntimeException("fail 1") - - x = "56" - - if (!a.isSetValueCalled || !a.isProvideDelegateCalled) throw RuntimeException("fail 2") -} +//suspend fun foo1() { +// var x by a +// +// if (x != "OK") throw RuntimeException("fail 1") +// +// x = "56" +// +// if (!a.isSetValueCalled || !a.isProvideDelegateCalled) throw RuntimeException("fail 2") +//} suspend fun foo2() { val (y) = a @@ -90,11 +91,10 @@ suspend fun foo4() { if (y != "OK") throw RuntimeException("fail 5") } -// TODO: KT-15930 -//suspend fun foo5() { -// a -= "56" -// if (!a.isMinusAssignCalled) throw RuntimeException("fail 6") -//} +suspend fun foo5() { + a -= "56" + if (!a.isMinusAssignCalled) throw RuntimeException("fail 6") +} suspend fun foo6() { var y = a++ @@ -126,11 +126,11 @@ suspend fun foo9() { fun box(): String { builder { - foo1() + //foo1() foo2() foo3() foo4() - //foo5() + foo5() foo6() foo7() //foo8() diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.kt index 3deb4c35b4e..6224ec56810 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.kt @@ -4,5 +4,5 @@ fun bar(d: Delegate): String { } class Delegate { - suspend operator fun getValue(thisRef: Any?, property: Any?): String = "" + suspend operator fun getValue(thisRef: Any?, property: Any?): String = "" } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.kt index d643a8a8e78..7591f3ee18c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.kt @@ -1,11 +1,43 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER // SKIP_TXT +import kotlin.reflect.KProperty + class A { suspend operator fun get(x: Int) = 1 suspend operator fun set(x: Int, v: String) {} operator suspend fun contains(y: String): Boolean = true + + suspend operator fun unaryPlus() = this + suspend operator fun unaryMinus() = this + suspend operator fun not() = this + suspend operator fun inc() = this + suspend operator fun dec() = this + + suspend operator fun plus(a: A) = a + suspend operator fun minus(a: A) = a + suspend operator fun times(a: A) = a + suspend operator fun div(a: A) = a + suspend operator fun rem(a: A) = a + suspend operator fun rangeTo(a: A) = a + + suspend operator fun invoke(a: A) = a + + suspend operator fun compareTo(a: A) = hashCode().compareTo(a.hashCode()) + + suspend operator fun iterator() = this + suspend operator fun hasNext() = false + suspend operator fun next() = this + + suspend operator fun contains(b: A) = this == b + suspend operator fun get(a: A) = a + suspend operator fun equals(a: A) = a === this + suspend operator fun set(a: A, b: A) {} + + suspend operator fun provideDelegate(a: A, p: KProperty<*>) = a + suspend operator fun getValue(a: A, p: KProperty<*>) = a + suspend operator fun setValue(a: A, p: KProperty<*>, b: A) {} } class B