From 2e7dcd6096bfda1e84da31b337ee4d67e53e42f7 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Wed, 20 Sep 2023 17:00:14 +0300 Subject: [PATCH] [FIR] Require overrides to have matching `isSuspend` flag value ^KT-57100 Fixed --- .../kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt | 2 ++ .../simple/mixingSuspendAndNonSuspendSupertypes.kt | 2 +- .../mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt | 2 +- ...xingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt | 2 +- .../mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt | 2 +- .../suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt | 2 +- .../mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt | 2 +- ...xingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt | 2 +- .../mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt | 2 +- .../testData/diagnostics/tests/suspendConflictingOverloads.kt | 2 +- .../testsWithStdLib/coroutines/mixingSuspendability.kt | 2 +- .../testsWithStdLib/coroutines/suspendOverridability.kt | 4 ++-- .../checkers/mixingComposableAndNormalFunctions.kt | 2 +- 13 files changed, 15 insertions(+), 13 deletions(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt index 07e6b359b36..7121b8e194b 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/scopes/impl/FirStandardOverrideChecker.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.scopes.impl import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.utils.isSuspend import org.jetbrains.kotlin.fir.declarations.utils.visibility import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclaration @@ -127,6 +128,7 @@ class FirStandardOverrideChecker(private val session: FirSession) : FirAbstractO fun isOverriddenFunction(overrideCandidate: FirSimpleFunction, baseDeclaration: FirSimpleFunction, ignoreVisibility: Boolean): Boolean { if (overrideCandidate.valueParameters.size != baseDeclaration.valueParameters.size) return false + if (overrideCandidate.isSuspend != baseDeclaration.isSuspend) return false val substitutor = buildTypeParametersSubstitutorIfCompatible(overrideCandidate, baseDeclaration) ?: return false diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt index a3996f00cca..157cbcec5a2 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypes.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS class C: suspend () -> Unit, () -> Unit { override suspend fun invoke() { diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt index e64359870c3..8684e6aa1be 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS abstract class CSuper: () -> Unit diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt index 34055071d13..412bd519160 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS fun interface FISuper: () -> Unit diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt index 938700fcab0..2d5398a29d8 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/simple/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS interface ISuper: () -> Unit diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt index b95074a3f6a..5c4e3813bd1 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypes.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS import kotlin.coroutines.* class C: SuspendFunction0, () -> Unit { diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt index b3b96a57155..8c3778a07e3 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperClass.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS import kotlin.coroutines.* diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt index 1810f4c5afa..93eda96908a 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperFunInterface.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS import kotlin.coroutines.* diff --git a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt index 638329b25b6..db337316daa 100644 --- a/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt +++ b/compiler/testData/diagnostics/tests/coroutines/suspendFunctionAsSupertype/suspendFunctionN/mixingSuspendAndNonSuspendSupertypesThruSuperinterface.kt @@ -1,7 +1,7 @@ // FIR_IDENTICAL // !LANGUAGE: +SuspendFunctionAsSupertype // SKIP_TXT -// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS +// DIAGNOSTICS: -CONFLICTING_INHERITED_MEMBERS, -CONFLICTING_OVERLOADS, -ABSTRACT_MEMBER_NOT_IMPLEMENTED, -FUN_INTERFACE_WRONG_COUNT_OF_ABSTRACT_MEMBERS import kotlin.coroutines.* diff --git a/compiler/testData/diagnostics/tests/suspendConflictingOverloads.kt b/compiler/testData/diagnostics/tests/suspendConflictingOverloads.kt index 8167db43658..72d72ab4e0d 100644 --- a/compiler/testData/diagnostics/tests/suspendConflictingOverloads.kt +++ b/compiler/testData/diagnostics/tests/suspendConflictingOverloads.kt @@ -11,5 +11,5 @@ interface C07I02{ } class C07C01: C07I01, C07I02 { - override fun some() {} + override fun some() {} } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.kt index ef8236f4800..e15459e9f42 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/mixingSuspendability.kt @@ -2,6 +2,6 @@ interface AsyncVal { suspend fun getVal(): Int = 1} interface SyncVal { fun getVal(): Int = 1 } -class MixSuspend : AsyncVal, SyncVal { +class MixSuspend : AsyncVal, SyncVal { } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt index e9b8f971f93..0661c733770 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/suspendOverridability.kt @@ -6,11 +6,11 @@ interface A { } interface B : A { - override fun foo() { + override fun foo() { } - override suspend fun bar() { + override suspend fun bar() { } } diff --git a/plugins/fir-plugin-prototype/testData/diagnostics/checkers/mixingComposableAndNormalFunctions.kt b/plugins/fir-plugin-prototype/testData/diagnostics/checkers/mixingComposableAndNormalFunctions.kt index bc9c3ad1e22..cb2b3ae10c8 100644 --- a/plugins/fir-plugin-prototype/testData/diagnostics/checkers/mixingComposableAndNormalFunctions.kt +++ b/plugins/fir-plugin-prototype/testData/diagnostics/checkers/mixingComposableAndNormalFunctions.kt @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.fir.plugin.MyComposable import kotlin.reflect.* -abstract class MyClass: KSuspendFunction0, () -> Unit +abstract class MyClass: KSuspendFunction0, () -> Unit abstract class OurClass: @MyComposable (Int) -> Unit, () -> Unit abstract class YourClass: @MyComposable KFunction1, () -> Unit