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 c77cb3516d2..5db974d7ab7 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 @@ -10054,6 +10054,28 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/functionLiterals/suspend") + @TestDataPath("$PROJECT_ROOT") + public class Suspend extends AbstractFirDiagnosticTest { + @Test + public void testAllFilesPresentInSuspend() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/functionLiterals/suspend"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("disabled.kt") + public void testDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt"); + } + + @Test + @TestMetadata("enabled.kt") + public void testEnabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt"); + } + } } @Nested diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt index b6b4648f2d8..09f5494a82a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/FunInterfaceDeclarationChecker.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.resolve.checkers import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor @@ -60,7 +61,10 @@ class FunInterfaceDeclarationChecker : DeclarationChecker { ) { val ktFunction = abstractMember.source.getPsi() as? KtNamedFunction - if (abstractMember.isSuspend) { + if (abstractMember.isSuspend && + !(context.languageVersionSettings.supportsFeature(LanguageFeature.SuspendFunctionsInFunInterfaces) && + context.languageVersionSettings.supportsFeature(LanguageFeature.JvmIrEnabledByDefault)) + ) { val reportOn = ktFunction?.modifierList?.getModifier(KtTokens.SUSPEND_KEYWORD) ?: funInterfaceKeyword context.trace.report(Errors.FUN_INTERFACE_WITH_SUSPEND_FUNCTION.on(reportOn)) return diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.fir.kt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.fir.kt new file mode 100644 index 00000000000..bed693bc60e --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.fir.kt @@ -0,0 +1,5 @@ +// LANGUAGE: -SuspendFunctionsInFunInterfaces, +JvmIrEnabledByDefault + +fun interface I { + suspend fun foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt new file mode 100644 index 00000000000..13dbacc491d --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt @@ -0,0 +1,5 @@ +// LANGUAGE: -SuspendFunctionsInFunInterfaces, +JvmIrEnabledByDefault + +fun interface I { + suspend fun foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.txt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.txt new file mode 100644 index 00000000000..a191729edc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.txt @@ -0,0 +1,8 @@ +package + +public fun interface I { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract suspend fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt new file mode 100644 index 00000000000..04b3a511767 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt @@ -0,0 +1,6 @@ +// FIR_IDENTICAL +// LANGUAGE: +SuspendFunctionsInFunInterfaces, +JvmIrEnabledByDefault + +fun interface I { + suspend fun foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.txt b/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.txt new file mode 100644 index 00000000000..a191729edc7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.txt @@ -0,0 +1,8 @@ +package + +public fun interface I { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract suspend fun foo(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} 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 a975a69d80f..6a69a0267a1 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 @@ -10060,6 +10060,28 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/functionLiterals/return/unresolvedReferenceInReturnBlock.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/tests/functionLiterals/suspend") + @TestDataPath("$PROJECT_ROOT") + public class Suspend extends AbstractDiagnosticTest { + @Test + public void testAllFilesPresentInSuspend() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/functionLiterals/suspend"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true); + } + + @Test + @TestMetadata("disabled.kt") + public void testDisabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/disabled.kt"); + } + + @Test + @TestMetadata("enabled.kt") + public void testEnabled() throws Exception { + runTest("compiler/testData/diagnostics/tests/functionLiterals/suspend/enabled.kt"); + } + } } @Nested diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index bebb209059d..04fcbd8d981 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -198,6 +198,7 @@ enum class LanguageFeature( InlineClasses(sinceVersion = KOTLIN_1_3, defaultState = State.ENABLED_WITH_WARNING, kind = UNSTABLE_FEATURE), JvmInlineValueClasses(sinceVersion = KOTLIN_1_5, defaultState = State.ENABLED, kind = OTHER), + SuspendFunctionsInFunInterfaces(sinceVersion = KOTLIN_1_5, defaultState = State.ENABLED, kind = OTHER), ; val presentableName: String