Support 'interceptResume' operator in frontend
#KT-14891 In Progress
This commit is contained in:
@@ -71,4 +71,7 @@ object OperatorModifierChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val COROUTINE_OPERATOR_NAMES =
|
private val COROUTINE_OPERATOR_NAMES =
|
||||||
setOf(OperatorNameConventions.COROUTINE_HANDLE_RESULT, OperatorNameConventions.COROUTINE_HANDLE_EXCEPTION)
|
setOf(OperatorNameConventions.COROUTINE_HANDLE_RESULT,
|
||||||
|
OperatorNameConventions.COROUTINE_HANDLE_EXCEPTION,
|
||||||
|
OperatorNameConventions.COROUTINE_INTERCEPT_RESUME
|
||||||
|
)
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
class A1 {
|
||||||
|
operator fun interceptResume(x: () -> Unit) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun A1.interceptResume(x: () -> Unit) {}
|
||||||
|
|
||||||
|
class A2 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun interceptResume(x: () -> Unit, w: Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A3 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun interceptResume(x: String.() -> Unit) = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
class A4 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun interceptResume(x: (String) -> Unit) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A5 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun interceptResume(x: () -> Int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A6 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun <T> interceptResume(x: () -> Unit) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A7 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun interceptResume(x: () -> Unit = {}) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A8 {
|
||||||
|
<!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun interceptResume(vararg x: () -> Unit) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
class A9 {
|
||||||
|
inline operator fun interceptResume(x: () -> Unit) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public operator fun A1.interceptResume(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||||
|
|
||||||
|
public final class A1 {
|
||||||
|
public constructor A1()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A2 {
|
||||||
|
public constructor A2()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: () -> kotlin.Unit, /*1*/ w: kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A3 {
|
||||||
|
public constructor A3()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: kotlin.String.() -> kotlin.Unit): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A4 {
|
||||||
|
public constructor A4()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: (kotlin.String) -> kotlin.Unit): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A5 {
|
||||||
|
public constructor A5()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: () -> kotlin.Int): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A6 {
|
||||||
|
public constructor A6()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun </*0*/ T> interceptResume(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A7 {
|
||||||
|
public constructor A7()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: () -> kotlin.Unit = ...): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A8 {
|
||||||
|
public constructor A8()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ vararg x: () -> kotlin.Unit /*kotlin.Array<out () -> kotlin.Unit>*/): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class A9 {
|
||||||
|
public constructor A9()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator inline fun interceptResume(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -10,6 +10,9 @@ class Controller {
|
|||||||
|
|
||||||
<!UNSUPPORTED_FEATURE!>operator<!> fun handleException(x: Throwable, y: Continuation<Nothing>) {
|
<!UNSUPPORTED_FEATURE!>operator<!> fun handleException(x: Throwable, y: Continuation<Nothing>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
<!UNSUPPORTED_FEATURE!>operator<!> fun interceptResume(x: () -> Unit) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun builder(<!UNSUPPORTED_FEATURE!>coroutine<!> c: Controller.() -> Continuation<Unit>) {
|
fun builder(<!UNSUPPORTED_FEATURE!>coroutine<!> c: Controller.() -> Continuation<Unit>) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ public final class Controller {
|
|||||||
public final operator fun handleException(/*0*/ x: kotlin.Throwable, /*1*/ y: kotlin.coroutines.Continuation<kotlin.Nothing>): kotlin.Unit
|
public final operator fun handleException(/*0*/ x: kotlin.Throwable, /*1*/ y: kotlin.coroutines.Continuation<kotlin.Nothing>): kotlin.Unit
|
||||||
public final operator fun handleResult(/*0*/ x: kotlin.String, /*1*/ y: kotlin.coroutines.Continuation<kotlin.Nothing>): kotlin.Unit
|
public final operator fun handleResult(/*0*/ x: kotlin.String, /*1*/ y: kotlin.coroutines.Continuation<kotlin.Nothing>): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public final operator fun interceptResume(/*0*/ x: () -> kotlin.Unit): kotlin.Unit
|
||||||
public final suspend fun suspendHere(/*0*/ x: kotlin.coroutines.Continuation<kotlin.String>): kotlin.Unit
|
public final suspend fun suspendHere(/*0*/ x: kotlin.coroutines.Continuation<kotlin.String>): kotlin.Unit
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4234,6 +4234,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("interceptResume.kt")
|
||||||
|
public void testInterceptResume() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/interceptResume.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("irrelevantSuspendDeclarations.kt")
|
@TestMetadata("irrelevantSuspendDeclarations.kt")
|
||||||
public void testIrrelevantSuspendDeclarations() throws Exception {
|
public void testIrrelevantSuspendDeclarations() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/irrelevantSuspendDeclarations.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/coroutines/irrelevantSuspendDeclarations.kt");
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ object OperatorNameConventions {
|
|||||||
@JvmField val MINUS_ASSIGN = Name.identifier("minusAssign")
|
@JvmField val MINUS_ASSIGN = Name.identifier("minusAssign")
|
||||||
@JvmField val COROUTINE_HANDLE_RESULT = Name.identifier("handleResult")
|
@JvmField val COROUTINE_HANDLE_RESULT = Name.identifier("handleResult")
|
||||||
@JvmField val COROUTINE_HANDLE_EXCEPTION = Name.identifier("handleException")
|
@JvmField val COROUTINE_HANDLE_EXCEPTION = Name.identifier("handleException")
|
||||||
|
@JvmField val COROUTINE_INTERCEPT_RESUME = Name.identifier("interceptResume")
|
||||||
|
|
||||||
|
|
||||||
@JvmField val PROPERTY_DELEGATED = Name.identifier("propertyDelegated")
|
@JvmField val PROPERTY_DELEGATED = Name.identifier("propertyDelegated")
|
||||||
|
|
||||||
|
|||||||
@@ -16,8 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.util
|
package org.jetbrains.kotlin.util
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.*
|
||||||
import org.jetbrains.kotlin.builtins.ReflectionTypes
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
@@ -37,6 +36,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions.COMPONENT_REGEX
|
|||||||
import org.jetbrains.kotlin.util.OperatorNameConventions.CONTAINS
|
import org.jetbrains.kotlin.util.OperatorNameConventions.CONTAINS
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_HANDLE_EXCEPTION
|
import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_HANDLE_EXCEPTION
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_HANDLE_RESULT
|
import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_HANDLE_RESULT
|
||||||
|
import org.jetbrains.kotlin.util.OperatorNameConventions.COROUTINE_INTERCEPT_RESUME
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions.DEC
|
import org.jetbrains.kotlin.util.OperatorNameConventions.DEC
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions.EQUALS
|
import org.jetbrains.kotlin.util.OperatorNameConventions.EQUALS
|
||||||
import org.jetbrains.kotlin.util.OperatorNameConventions.GET
|
import org.jetbrains.kotlin.util.OperatorNameConventions.GET
|
||||||
@@ -163,7 +163,7 @@ internal class Checks private constructor(
|
|||||||
|
|
||||||
abstract class AbstractModifierChecks {
|
abstract class AbstractModifierChecks {
|
||||||
abstract internal val checks: List<Checks>
|
abstract internal val checks: List<Checks>
|
||||||
|
|
||||||
inline fun ensure(cond: Boolean, msg: () -> String) = if (!cond) msg() else null
|
inline fun ensure(cond: Boolean, msg: () -> String) = if (!cond) msg() else null
|
||||||
|
|
||||||
fun check(functionDescriptor: FunctionDescriptor): CheckResult {
|
fun check(functionDescriptor: FunctionDescriptor): CheckResult {
|
||||||
@@ -217,6 +217,14 @@ object OperatorChecks : AbstractModifierChecks() {
|
|||||||
"First parameter should be 'Throwable'"
|
"First parameter should be 'Throwable'"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Checks(COROUTINE_INTERCEPT_RESUME, Member, ValueParameterCountCheck.Equals(1), ReturnsUnit, NoDefaultAndVarargsCheck,
|
||||||
|
NoTypeParametersCheck
|
||||||
|
) {
|
||||||
|
val parameterType = valueParameters.single().type
|
||||||
|
ensure(parameterType.isNonExtensionFunctionType && parameterType.getValueParameterTypesFromFunctionType().isEmpty() &&
|
||||||
|
parameterType.getReturnTypeFromFunctionType().isUnit()
|
||||||
|
) { "Value parameter must have a functional type '() -> Unit'" }
|
||||||
|
},
|
||||||
Checks(PROPERTY_DELEGATED, Member, ValueParameterCountCheck.Equals(1)) //TODO: more checks required!
|
Checks(PROPERTY_DELEGATED, Member, ValueParameterCountCheck.Equals(1)) //TODO: more checks required!
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -236,4 +244,4 @@ object InfixChecks : AbstractModifierChecks() {
|
|||||||
Checks(MemberKindCheck.MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck))
|
Checks(MemberKindCheck.MemberOrExtension, SingleValueParameter, NoDefaultAndVarargsCheck))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FunctionDescriptor.isValidOperator() = isOperator && OperatorChecks.check(this).isSuccess
|
fun FunctionDescriptor.isValidOperator() = isOperator && OperatorChecks.check(this).isSuccess
|
||||||
|
|||||||
Reference in New Issue
Block a user