Support extensions in functional supertypes
Under a flag for now.
This commit is contained in:
committed by
teamcityserver
parent
10101dc2b4
commit
3f8fa3149b
+6
@@ -29277,6 +29277,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("findClosestCorrespondingSupertype.kt")
|
||||
public void testFindClosestCorrespondingSupertype() throws Exception {
|
||||
|
||||
+6
@@ -29277,6 +29277,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("findClosestCorrespondingSupertype.kt")
|
||||
public void testFindClosestCorrespondingSupertype() throws Exception {
|
||||
|
||||
+6
@@ -29277,6 +29277,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("findClosestCorrespondingSupertype.kt")
|
||||
public void testFindClosestCorrespondingSupertype() throws Exception {
|
||||
|
||||
+5
-1
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
@@ -17,6 +18,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.withSuppressedDiagnostics
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
@@ -42,7 +44,9 @@ object FirSupertypesChecker : FirClassChecker() {
|
||||
reporter.reportOn(superTypeRef.source, FirErrors.NULLABLE_SUPERTYPE, context)
|
||||
nullableSupertypeReported = true
|
||||
}
|
||||
if (!extensionFunctionSupertypeReported && coneType.isExtensionFunctionType) {
|
||||
if (!extensionFunctionSupertypeReported && coneType.isExtensionFunctionType &&
|
||||
!context.session.languageVersionSettings.supportsFeature(LanguageFeature.FunctionalTypeWithExtensionAsSupertype)
|
||||
) {
|
||||
reporter.reportOn(superTypeRef.source, FirErrors.SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE, context)
|
||||
extensionFunctionSupertypeReported = true
|
||||
}
|
||||
|
||||
+6
@@ -15754,6 +15754,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
|
||||
@@ -583,7 +583,9 @@ public class BodyResolver {
|
||||
if (classDescriptor != null) {
|
||||
if (ErrorUtils.isError(classDescriptor)) continue;
|
||||
|
||||
if (FunctionTypesKt.isExtensionFunctionType(supertype)) {
|
||||
if (FunctionTypesKt.isExtensionFunctionType(supertype) &&
|
||||
!languageVersionSettings.supportsFeature(LanguageFeature.FunctionalTypeWithExtensionAsSupertype)
|
||||
) {
|
||||
trace.report(SUPERTYPE_IS_EXTENSION_FUNCTION_TYPE.on(typeReference));
|
||||
}
|
||||
else if (FunctionTypesKt.isSuspendFunctionType(supertype) &&
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// !LANGUAGE: +FunctionalTypeWithExtensionAsSupertype
|
||||
// IGNORE_BACKEND: JS, JS_IR, WASM
|
||||
|
||||
interface I: (String) -> String
|
||||
|
||||
class C: String.() -> String, I {
|
||||
override fun invoke(p1: String): String = p1
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val c = C()
|
||||
if (c("OK") != "OK") return c("OK")
|
||||
val ext: String.() -> String = c
|
||||
return "OK".ext()
|
||||
}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +FunctionalTypeWithExtensionAsSupertype
|
||||
// SKIP_TXT
|
||||
class A : Double.() -> Unit {
|
||||
override fun invoke(p1: Double) {}
|
||||
}
|
||||
|
||||
class B : Int.(Double) -> Unit {
|
||||
override fun invoke(p1: Int, p2: Double) {}
|
||||
}
|
||||
|
||||
open class C {}
|
||||
|
||||
abstract class A0 : C.() -> Int
|
||||
abstract class A1 : C.(Int) -> Int
|
||||
abstract class A2 : C.(Int, String) -> Int
|
||||
|
||||
open class D<T> {}
|
||||
|
||||
abstract class B0<T> : D<T>.() -> Int
|
||||
abstract class B1<T> : D<T>.(C) -> Int
|
||||
abstract class B2<T> : D<T>.(T, C) -> T
|
||||
|
||||
interface E<T> {}
|
||||
|
||||
abstract class C0: C(), Int.() -> Double
|
||||
abstract class C1<T>: C(), E<T>, Int.(C) -> Double
|
||||
Generated
+6
@@ -29373,6 +29373,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extFunctionTypeAsSuperTypeRestrictionLifted.kt")
|
||||
public void testExtFunctionTypeAsSuperTypeRestrictionLifted() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("findClosestCorrespondingSupertype.kt")
|
||||
public void testFindClosestCorrespondingSupertype() throws Exception {
|
||||
|
||||
+6
@@ -15676,6 +15676,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
|
||||
+6
@@ -15754,6 +15754,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
|
||||
+5
@@ -12889,6 +12889,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/kt1061.kt");
|
||||
|
||||
@@ -253,6 +253,7 @@ enum class LanguageFeature(
|
||||
InlineClasses(KOTLIN_1_3, defaultState = State.ENABLED_WITH_WARNING, kind = UNSTABLE_FEATURE),
|
||||
ProhibitComparisonOfIncompatibleClasses(sinceVersion = null, kind = BUG_FIX, defaultState = State.DISABLED),
|
||||
ExplicitBackingFields(sinceVersion = null, defaultState = State.DISABLED, kind = UNSTABLE_FEATURE),
|
||||
FunctionalTypeWithExtensionAsSupertype(sinceVersion = KOTLIN_1_6, defaultState = State.DISABLED),
|
||||
|
||||
;
|
||||
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java
Generated
+5
@@ -11408,6 +11408,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/kt1061.kt");
|
||||
|
||||
Generated
+5
@@ -10814,6 +10814,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/kt1061.kt");
|
||||
|
||||
Generated
+5
@@ -10779,6 +10779,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/kt1061.kt");
|
||||
|
||||
js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java
Generated
+5
@@ -10075,6 +10075,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/executionOrder.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionAsSupertype.kt")
|
||||
public void testExtensionFunctionAsSupertype() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1061.kt")
|
||||
public void testKt1061() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/extensionFunctions/kt1061.kt");
|
||||
|
||||
Reference in New Issue
Block a user