diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/OperatorFunctionChecks.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/OperatorFunctionChecks.kt index 5c908538d2e..54a86a42402 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/OperatorFunctionChecks.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/OperatorFunctionChecks.kt @@ -9,6 +9,7 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.containingClassLookupTag import org.jetbrains.kotlin.fir.declarations.utils.isInline +import org.jetbrains.kotlin.fir.declarations.utils.isSuspend import org.jetbrains.kotlin.fir.languageVersionSettings import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.defaultType @@ -54,19 +55,22 @@ object OperatorFunctionChecks { OperatorNameConventions.GET_VALUE, Checks.memberOrExtension, Checks.noDefaultAndVarargs, Checks.ValueParametersCount.atLeast(2), - Checks.isKProperty + Checks.isKProperty, + Checks.nonSuspend, ) checkFor( OperatorNameConventions.SET_VALUE, Checks.memberOrExtension, Checks.noDefaultAndVarargs, Checks.ValueParametersCount.atLeast(3), - Checks.isKProperty + Checks.isKProperty, + Checks.nonSuspend, ) checkFor( OperatorNameConventions.PROVIDE_DELEGATE, Checks.memberOrExtension, Checks.noDefaultAndVarargs, Checks.ValueParametersCount.exactly(2), - Checks.isKProperty + Checks.isKProperty, + Checks.nonSuspend, ) checkFor(OperatorNameConventions.INVOKE, Checks.memberOrExtension) checkFor( @@ -175,6 +179,10 @@ private object Checks { it.dispatchReceiverType != null } + val nonSuspend = simple("must not be suspend") { + !it.isSuspend + } + object ValueParametersCount { fun atLeast(n: Int) = simple("must have at least $n value parameter" + (if (n > 1) "s" else "")) { it.valueParameters.size >= n diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt index 3deb4c35b4e..4667d3d5780 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/illegalSuspendCallsForDelegated.fir.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.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt index 2f83974c558..897048c6d50 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/operators.fir.kt @@ -35,9 +35,9 @@ class 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) {} + 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