diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index a9c863f1bd7..274f6e20138 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 769ba6edc9b..870dd19eaeb 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -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 { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index e56aa15bf0b..35ef3768aa4 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -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 { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt index 2f5eeccc3b7..92fc7466a1b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/declaration/FirSupertypesChecker.kt @@ -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 } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 532d612fae8..3c56ac37c8b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java index 42ed4515c97..22cb52c9847 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BodyResolver.java @@ -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) && diff --git a/compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt b/compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt new file mode 100644 index 00000000000..72e5f377313 --- /dev/null +++ b/compiler/testData/codegen/box/extensionFunctions/extensionFunctionAsSupertype.kt @@ -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() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt b/compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt new file mode 100644 index 00000000000..05d324f32be --- /dev/null +++ b/compiler/testData/diagnostics/tests/subtyping/extFunctionTypeAsSuperTypeRestrictionLifted.kt @@ -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 {} + +abstract class B0 : D.() -> Int +abstract class B1 : D.(C) -> Int +abstract class B2 : D.(T, C) -> T + +interface E {} + +abstract class C0: C(), Int.() -> Double +abstract class C1: C(), E, Int.(C) -> Double diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index ba60e33b315..08364b4a459 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -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 { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index a1530c7410d..2d643e27707 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index be1326a208f..4a5a907139e 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -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 { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 9f5dd59475b..475076c5fba 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -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"); diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index 2d955cae41b..dbfad9b1cbb 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.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), ; diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index cb98a76f910..74e0380c7eb 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 46432a78971..8aaa191c19f 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 743b72c308b..4d4561fc2b4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -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"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index f0f3179f63d..42b4ed08fee 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -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");