[FIR] Forbid suspend operator get/setValue and provideDelegate
#KT-58989 Fixed
This commit is contained in:
committed by
Space Team
parent
aea8bac7d2
commit
ca022cf4dc
+11
-3
@@ -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
|
||||
|
||||
Vendored
+1
-1
@@ -4,5 +4,5 @@ fun bar(d: Delegate): String {
|
||||
}
|
||||
|
||||
class Delegate {
|
||||
suspend operator fun getValue(thisRef: Any?, property: Any?): String = ""
|
||||
suspend <!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun getValue(thisRef: Any?, property: Any?): String = ""
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ class A {
|
||||
suspend <!INAPPLICABLE_OPERATOR_MODIFIER!>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 <!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun provideDelegate(a: A, p: KProperty<*>) = a
|
||||
suspend <!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun getValue(a: A, p: KProperty<*>) = a
|
||||
suspend <!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun setValue(a: A, p: KProperty<*>, b: A) {}
|
||||
}
|
||||
|
||||
class B
|
||||
|
||||
Reference in New Issue
Block a user