Forbid numbered KSuspendFunction interfaces usage as supertypes
#KT-24853 Fixed
This commit is contained in:
@@ -291,6 +291,7 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_NOT_A_CLASS_OR_INTERFACE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtTypeReference> SUPERTYPE_NOT_A_CLASS_OR_INTERFACE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
||||||
|
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<KtTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtTypeReference> MANY_CLASSES_IN_SUPERTYPE_LIST = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtTypeReference> SUPERTYPE_APPEARS_TWICE = DiagnosticFactory0.create(ERROR);
|
||||||
|
|||||||
+1
@@ -573,6 +573,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, "Extension function type is not allowed as supertypes");
|
MAP.put(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, "Extension function type is not allowed as supertypes");
|
||||||
MAP.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes");
|
MAP.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes");
|
||||||
MAP.put(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE, "Suspend function type is not allowed as supertypes");
|
MAP.put(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE, "Suspend function type is not allowed as supertypes");
|
||||||
|
MAP.put(SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE, "KSuspendFunctionN interfaces are not allowed as supertypes");
|
||||||
MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes");
|
MAP.put(CLASS_IN_SUPERTYPE_FOR_ENUM, "Enum class cannot inherit from classes");
|
||||||
MAP.put(CONSTRUCTOR_IN_INTERFACE, "An interface may not have a constructor");
|
MAP.put(CONSTRUCTOR_IN_INTERFACE, "An interface may not have a constructor");
|
||||||
MAP.put(METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, "An interface may not implement a method of 'Any'");
|
MAP.put(METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, "An interface may not implement a method of 'Any'");
|
||||||
|
|||||||
@@ -559,6 +559,9 @@ public class BodyResolver {
|
|||||||
else if (FunctionTypesKt.isSuspendFunctionType(supertype)) {
|
else if (FunctionTypesKt.isSuspendFunctionType(supertype)) {
|
||||||
trace.report(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE.on(typeReference));
|
trace.report(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE.on(typeReference));
|
||||||
}
|
}
|
||||||
|
else if (FunctionTypesKt.isKSuspendFunctionType(supertype)) {
|
||||||
|
trace.report(SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE.on(typeReference));
|
||||||
|
}
|
||||||
|
|
||||||
if (classDescriptor.getKind() != ClassKind.INTERFACE) {
|
if (classDescriptor.getKind() != ClassKind.INTERFACE) {
|
||||||
if (supertypeOwner.getKind() == ClassKind.ENUM_CLASS) {
|
if (supertypeOwner.getKind() == ClassKind.ENUM_CLASS) {
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// SKIP_TXT
|
||||||
|
|
||||||
|
import kotlin.reflect.*
|
||||||
|
|
||||||
|
<!ABSTRACT_MEMBER_NOT_IMPLEMENTED!>class A<!>: <!SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE!>KSuspendFunction0<Unit><!> {}
|
||||||
+5
@@ -1468,6 +1468,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kSuspendFunctionAsSupertype.kt")
|
||||||
|
public void testKSuspendFunctionAsSupertype() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt18292.kt")
|
@TestMetadata("kt18292.kt")
|
||||||
public void testKt18292_1_2() throws Exception {
|
public void testKt18292_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -1468,6 +1468,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/irrelevantSuspendDeclarations.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kSuspendFunctionAsSupertype.kt")
|
||||||
|
public void testKSuspendFunctionAsSupertype() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/kSuspendFunctionAsSupertype.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt18292.kt")
|
@TestMetadata("kt18292.kt")
|
||||||
public void testKt18292_1_2() throws Exception {
|
public void testKt18292_1_2() throws Exception {
|
||||||
runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.kt", "kotlin.coroutines.experimental");
|
runTestWithPackageReplacement("compiler/testData/diagnostics/testsWithStdLib/coroutines/kt18292.kt", "kotlin.coroutines.experimental");
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ val KotlinType.isFunctionType: Boolean
|
|||||||
val KotlinType.isSuspendFunctionType: Boolean
|
val KotlinType.isSuspendFunctionType: Boolean
|
||||||
get() = constructor.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction
|
get() = constructor.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.SuspendFunction
|
||||||
|
|
||||||
|
val KotlinType.isKSuspendFunctionType: Boolean
|
||||||
|
get() = constructor.declarationDescriptor?.getFunctionalClassKind() == FunctionClassDescriptor.Kind.KSuspendFunction
|
||||||
|
|
||||||
val KotlinType.isFunctionOrSuspendFunctionType: Boolean
|
val KotlinType.isFunctionOrSuspendFunctionType: Boolean
|
||||||
get() = isFunctionType || isSuspendFunctionType
|
get() = isFunctionType || isSuspendFunctionType
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user