Warn about suspend extension functional types as supertypes
They will become error in 2.0 #KT-58529 Fixed #KT-49175 Fixed
This commit is contained in:
+12
@@ -32016,6 +32016,18 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperType.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAnonymousObjects.kt")
|
||||
public void testTopLevelAnonymousObjects() throws Exception {
|
||||
|
||||
+12
@@ -32016,6 +32016,18 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperType.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAnonymousObjects.kt")
|
||||
public void testTopLevelAnonymousObjects() throws Exception {
|
||||
|
||||
+12
@@ -32016,6 +32016,18 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperType.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAnonymousObjects.kt")
|
||||
public void testTopLevelAnonymousObjects() throws Exception {
|
||||
|
||||
+12
@@ -32112,6 +32112,18 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperType.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAnonymousObjects.kt")
|
||||
public void testTopLevelAnonymousObjects() throws Exception {
|
||||
|
||||
@@ -390,6 +390,8 @@ public interface Errors {
|
||||
|
||||
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_SUSPEND_EXTENSION_FUNCTION_TYPE = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> MIXING_SUSPEND_AND_NON_SUSPEND_SUPERTYPES = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
+1
@@ -741,6 +741,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(MANY_CLASSES_IN_SUPERTYPE_LIST, "Only one class may appear in a supertype list");
|
||||
MAP.put(SUPERTYPE_NOT_A_CLASS_OR_INTERFACE, "Only classes and interfaces may serve as supertypes");
|
||||
MAP.put(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, "Extension function type is not allowed as supertypes");
|
||||
MAP.put(SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE, "Suspend extension function type is not allowed as supertypes. Such code will become error in future releases.");
|
||||
MAP.put(SUPERTYPE_INITIALIZED_IN_INTERFACE, "Interfaces cannot initialize supertypes");
|
||||
MAP.put(SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE, "Suspend function type is allowed as a supertype only since version 1.6");
|
||||
MAP.put(SUPERTYPE_IS_KSUSPEND_FUNCTION_TYPE, "KSuspendFunctionN interfaces are not allowed as supertypes");
|
||||
|
||||
@@ -591,6 +591,11 @@ public class BodyResolver {
|
||||
) {
|
||||
trace.report(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE.on(typeReference));
|
||||
}
|
||||
else if (FunctionTypesKt.isSuspendExtensionFunctionType(supertype) &&
|
||||
!languageVersionSettings.supportsFeature(LanguageFeature.FunctionalTypeWithExtensionAsSupertype) &&
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionAsSupertype)) {
|
||||
trace.report(SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE.on(typeReference));
|
||||
}
|
||||
else if (FunctionTypesKt.isSuspendFunctionType(supertype) &&
|
||||
!languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionAsSupertype)
|
||||
) {
|
||||
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
class A : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend Double.() -> Unit<!> {
|
||||
override suspend fun invoke(p1: Double) {}
|
||||
}
|
||||
|
||||
class B : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend Int.(Double) -> Unit<!> {
|
||||
override suspend fun invoke(p1: Int, p2: Double) {}
|
||||
}
|
||||
|
||||
open class C {}
|
||||
|
||||
abstract class A0 : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend C.() -> Int<!>
|
||||
abstract class A1 : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend C.(Int) -> Int<!>
|
||||
abstract class A2 : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend C.(Int, String) -> Int<!>
|
||||
|
||||
open class D<T> {}
|
||||
|
||||
abstract class B0<T> : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend D<T>.() -> Int<!>
|
||||
abstract class B1<T> : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend D<T>.(C) -> Int<!>
|
||||
abstract class B2<T> : <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend D<T>.(T, C) -> T<!>
|
||||
|
||||
interface E<T> {}
|
||||
|
||||
abstract class C0: C(), <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend Int.() -> Double<!>
|
||||
abstract class C1<T>: C(), E<T>, <!SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE!>suspend Int.(C) -> Double<!>
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
class A : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend Double.() -> Unit<!> {
|
||||
override suspend fun invoke(p1: Double) {}
|
||||
}
|
||||
|
||||
class B : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend Int.(Double) -> Unit<!> {
|
||||
override suspend fun invoke(p1: Int, p2: Double) {}
|
||||
}
|
||||
|
||||
open class C {}
|
||||
|
||||
abstract class A0 : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend C.() -> Int<!>
|
||||
abstract class A1 : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend C.(Int) -> Int<!>
|
||||
abstract class A2 : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend C.(Int, String) -> Int<!>
|
||||
|
||||
open class D<T> {}
|
||||
|
||||
abstract class B0<T> : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend D<T>.() -> Int<!>
|
||||
abstract class B1<T> : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend D<T>.(C) -> Int<!>
|
||||
abstract class B2<T> : <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend D<T>.(T, C) -> T<!>
|
||||
|
||||
interface E<T> {}
|
||||
|
||||
abstract class C0: C(), <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend Int.() -> Double<!>
|
||||
abstract class C1<T>: C(), E<T>, <!SUPERTYPE_IS_SUSPEND_EXTENSION_FUNCTION_TYPE!>suspend Int.(C) -> Double<!>
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +FunctionalTypeWithExtensionAsSupertype
|
||||
class A : suspend Double.() -> Unit {
|
||||
override suspend fun invoke(p1: Double) {}
|
||||
}
|
||||
|
||||
class B : suspend Int.(Double) -> Unit {
|
||||
override suspend fun invoke(p1: Int, p2: Double) {}
|
||||
}
|
||||
|
||||
open class C {}
|
||||
|
||||
abstract class A0 : suspend C.() -> Int
|
||||
abstract class A1 : suspend C.(Int) -> Int
|
||||
abstract class A2 : suspend C.(Int, String) -> Int
|
||||
|
||||
open class D<T> {}
|
||||
|
||||
abstract class B0<T> : suspend D<T>.() -> Int
|
||||
abstract class B1<T> : suspend D<T>.(C) -> Int
|
||||
abstract class B2<T> : suspend D<T>.(T, C) -> T
|
||||
|
||||
interface E<T> {}
|
||||
|
||||
abstract class C0: C(), suspend Int.() -> Double
|
||||
abstract class C1<T>: C(), E<T>, suspend Int.(C) -> Double
|
||||
Generated
+12
@@ -32884,6 +32884,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/nestedLocalClasses.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperType.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testSuspendExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/suspendExtFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("topLevelAnonymousObjects.kt")
|
||||
public void testTopLevelAnonymousObjects() throws Exception {
|
||||
|
||||
@@ -104,6 +104,9 @@ val KotlinType.isNonExtensionFunctionType: Boolean
|
||||
val KotlinType.isExtensionFunctionType: Boolean
|
||||
get() = isFunctionType && isTypeAnnotatedWithExtensionFunctionType
|
||||
|
||||
val KotlinType.isSuspendExtensionFunctionType: Boolean
|
||||
get() = isSuspendFunctionType && isTypeAnnotatedWithExtensionFunctionType
|
||||
|
||||
val KotlinType.isBuiltinExtensionFunctionalType: Boolean
|
||||
get() = isBuiltinFunctionalType && isTypeAnnotatedWithExtensionFunctionType
|
||||
|
||||
|
||||
Reference in New Issue
Block a user