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 c5034a36d12..a3d33d28524 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 @@ -15921,12 +15921,36 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inline/stringTemplate.kt"); } + @Test + @TestMetadata("superCall.kt") + public void testSuperCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCall.kt"); + } + @Test @TestMetadata("superCallDepecation.kt") public void testSuperCallDepecation() throws Exception { runTest("compiler/testData/diagnostics/tests/inline/superCallDepecation.kt"); } + @Test + @TestMetadata("superCallDepecationWarning.kt") + public void testSuperCallDepecationWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.kt"); + } + + @Test + @TestMetadata("superCallFromMultipleSubclasses.kt") + public void testSuperCallFromMultipleSubclasses() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.kt"); + } + + @Test + @TestMetadata("superProperty.kt") + public void testSuperProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superProperty.kt"); + } + @Test @TestMetadata("unsupportedConstruction.kt") public void testUnsupportedConstruction() 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 cdfb8a062cb..69c1fe343ed 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 @@ -15921,12 +15921,36 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inline/stringTemplate.kt"); } + @Test + @TestMetadata("superCall.kt") + public void testSuperCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCall.kt"); + } + @Test @TestMetadata("superCallDepecation.kt") public void testSuperCallDepecation() throws Exception { runTest("compiler/testData/diagnostics/tests/inline/superCallDepecation.kt"); } + @Test + @TestMetadata("superCallDepecationWarning.kt") + public void testSuperCallDepecationWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.kt"); + } + + @Test + @TestMetadata("superCallFromMultipleSubclasses.kt") + public void testSuperCallFromMultipleSubclasses() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.kt"); + } + + @Test + @TestMetadata("superProperty.kt") + public void testSuperProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superProperty.kt"); + } + @Test @TestMetadata("unsupportedConstruction.kt") public void testUnsupportedConstruction() throws Exception { diff --git a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt index ece43e0cb12..12296d44669 100644 --- a/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt +++ b/compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/FirDiagnosticsList.kt @@ -1271,7 +1271,7 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") { parameter("referencedDeclaration") } - val SUPER_CALL_FROM_PUBLIC_INLINE by warning(PositioningStrategy.REFERENCE_BY_QUALIFIED) { + val SUPER_CALL_FROM_PUBLIC_INLINE by error(PositioningStrategy.REFERENCE_BY_QUALIFIED) { parameter("symbol") } diff --git a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index f77e16dbfcf..72db9ac9c64 100644 --- a/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -663,7 +663,7 @@ object FirErrors { val PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR by error2, FirBasedSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val PROTECTED_CALL_FROM_PUBLIC_INLINE by warning2, FirBasedSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val PRIVATE_CLASS_MEMBER_FROM_INLINE by error2, FirBasedSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) - val SUPER_CALL_FROM_PUBLIC_INLINE by warning1>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) + val SUPER_CALL_FROM_PUBLIC_INLINE by error1>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED) val DECLARATION_CANT_BE_INLINED by error0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE) val OVERRIDE_BY_INLINE by warning0(SourceElementPositioningStrategies.DECLARATION_SIGNATURE) val NON_INTERNAL_PUBLISHED_API by error0() diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 74dc2ed9720..4a07a994e92 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -1164,7 +1164,7 @@ public interface Errors { DiagnosticFactory0 NON_INTERNAL_PUBLISHED_API = DiagnosticFactory0.create(ERROR); DiagnosticFactoryForDeprecation1 PROTECTED_CALL_FROM_PUBLIC_INLINE = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitProtectedCallFromInline); DiagnosticFactory1 PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory1.create(WARNING); - DiagnosticFactory1 SUPER_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory1.create(WARNING); + DiagnosticFactoryForDeprecation1 SUPER_CALL_FROM_PUBLIC_INLINE = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitSuperCallsFromPublicInline); DiagnosticFactory2 INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE = DiagnosticFactory2.create(ERROR); DiagnosticFactory2 NOT_SUPPORTED_INLINE_PARAMETER_IN_INLINE_PARAMETER_DEFAULT_VALUE = DiagnosticFactory2.create(ERROR); DiagnosticFactory0 PRIVATE_INLINE_FUNCTIONS_RETURNING_ANONYMOUS_OBJECTS = DiagnosticFactory0.create(WARNING); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.kt index 81e507621a0..579ce80d239 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.kt @@ -316,7 +316,11 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC val descriptor = thisTypeForSuperCall.constructor.declarationDescriptor as? DeclarationDescriptorWithVisibility ?: return if (!isDefinedInInlineFunction(descriptor)) { - context.trace.report(SUPER_CALL_FROM_PUBLIC_INLINE.on(expression.parent.parent ?: superCall, callableDescriptor)) + context.trace.report( + SUPER_CALL_FROM_PUBLIC_INLINE.on( + context.languageVersionSettings, expression.parent.parent ?: superCall, callableDescriptor + ) + ) } } } diff --git a/compiler/testData/codegen/boxInline/syntheticAccessors/superCall.kt b/compiler/testData/codegen/boxInline/syntheticAccessors/superCall.kt index 98cf3d927ed..c8126efd40d 100644 --- a/compiler/testData/codegen/boxInline/syntheticAccessors/superCall.kt +++ b/compiler/testData/codegen/boxInline/syntheticAccessors/superCall.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProhibitSuperCallsFromPublicInline // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/syntheticAccessors/superCallFromMultipleSubclasses.kt b/compiler/testData/codegen/boxInline/syntheticAccessors/superCallFromMultipleSubclasses.kt index af640fd4a92..0dbe81cef22 100644 --- a/compiler/testData/codegen/boxInline/syntheticAccessors/superCallFromMultipleSubclasses.kt +++ b/compiler/testData/codegen/boxInline/syntheticAccessors/superCallFromMultipleSubclasses.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProhibitSuperCallsFromPublicInline // FILE: 1.kt package test diff --git a/compiler/testData/codegen/boxInline/syntheticAccessors/superProperty.kt b/compiler/testData/codegen/boxInline/syntheticAccessors/superProperty.kt index e5f900da71e..29d81c4331b 100644 --- a/compiler/testData/codegen/boxInline/syntheticAccessors/superProperty.kt +++ b/compiler/testData/codegen/boxInline/syntheticAccessors/superProperty.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: -ProhibitSuperCallsFromPublicInline // FILE: 1.kt package test diff --git a/compiler/testData/diagnostics/tests/inline/kt21177.fir.kt b/compiler/testData/diagnostics/tests/inline/kt21177.fir.kt new file mode 100644 index 00000000000..9d8dcdd28a1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/kt21177.fir.kt @@ -0,0 +1,18 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +class SomeContainer { + protected class Limit + + protected fun makeLimit(): Limit = TODO() + + public inline fun foo(f: () -> Unit) { + Limit() + makeLimit() + } +} + +open class A protected constructor() { + inline fun foo(f: () -> Unit) { + A() + } +} diff --git a/compiler/testData/diagnostics/tests/inline/kt21177.kt b/compiler/testData/diagnostics/tests/inline/kt21177.kt index 99a2ae566ee..9d8dcdd28a1 100644 --- a/compiler/testData/diagnostics/tests/inline/kt21177.kt +++ b/compiler/testData/diagnostics/tests/inline/kt21177.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // !DIAGNOSTICS: -UNUSED_PARAMETER class SomeContainer { diff --git a/compiler/testData/diagnostics/tests/inline/superCall.fir.kt b/compiler/testData/diagnostics/tests/inline/superCall.fir.kt new file mode 100644 index 00000000000..83aeba321f4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCall.fir.kt @@ -0,0 +1,25 @@ +// FILE: 1.kt + +package test + +open class A { + open fun test() = "OK" +} + +object X : A() { + override fun test(): String { + return "fail" + } + + inline fun doTest(): String { + return super.test() + } +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return X.doTest() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/superCall.kt b/compiler/testData/diagnostics/tests/inline/superCall.kt new file mode 100644 index 00000000000..1412f440def --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCall.kt @@ -0,0 +1,25 @@ +// FILE: 1.kt + +package test + +open class A { + open fun test() = "OK" +} + +object X : A() { + override fun test(): String { + return "fail" + } + + inline fun doTest(): String { + return super.test() + } +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return X.doTest() +} diff --git a/compiler/testData/diagnostics/tests/inline/superCall.txt b/compiler/testData/diagnostics/tests/inline/superCall.txt new file mode 100644 index 00000000000..5db2075ab36 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCall.txt @@ -0,0 +1,23 @@ +package + +public fun box(): kotlin.String + +package test { + + public open class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public object X : test.A { + private constructor X() + public final inline fun doTest(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/inline/superCallDepecation.kt b/compiler/testData/diagnostics/tests/inline/superCallDepecation.kt index 5fbb2dc1ed5..c47e89db0f6 100644 --- a/compiler/testData/diagnostics/tests/inline/superCallDepecation.kt +++ b/compiler/testData/diagnostics/tests/inline/superCallDepecation.kt @@ -7,21 +7,21 @@ open class AndroidTargetConfigurator : AndroidModuleConfigurator { public inline fun inlineFun(): String { - return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() } @PublishedApi internal inline fun inlineFunPublished(): String { - return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() } public inline fun inlineFunAnonymousObjects(): String { { - super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() }() return object { - fun run() = super@AndroidTargetConfigurator.classFun() + super@AndroidTargetConfigurator.getConfiguratorSettings() + super@AndroidTargetConfigurator.getConfiguratorSettings() + fun run() = super@AndroidTargetConfigurator.classFun() + super@AndroidTargetConfigurator.getConfiguratorSettings() + super@AndroidTargetConfigurator.getConfiguratorSettings() }.run() } @@ -94,7 +94,7 @@ sealed class FooSealed : Base() { class B: FooSealed() inline fun test() { - super.classFun() + super.classFun() } } @@ -103,7 +103,7 @@ enum class FooEmum { A, B { inline fun test() { - super.classFun() + super.classFun() } }; @@ -114,8 +114,8 @@ class FooOuter : Base() { inner class FooInner: Base() { inline fun test() { - super@FooOuter.classFun() - super.classFun() + super@FooOuter.classFun() + super.classFun() } } diff --git a/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.fir.kt b/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.fir.kt new file mode 100644 index 00000000000..25bb91c657f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.fir.kt @@ -0,0 +1,123 @@ +// !LANGUAGE: -ProhibitSuperCallsFromPublicInline +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE + +// FILE: main.kt +open class AndroidTargetConfigurator : + Base(), + ModuleConfiguratorWithTests, + AndroidModuleConfigurator { + + public inline fun inlineFun(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + @PublishedApi + internal inline fun inlineFunPublished(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + public inline fun inlineFunAnonymousObjects(): String { + { + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + }() + + return object { + fun run() = super@AndroidTargetConfigurator.classFun() + super@AndroidTargetConfigurator.getConfiguratorSettings() + super@AndroidTargetConfigurator.getConfiguratorSettings() + }.run() + } + + public inline fun inlineFunAnonymousNoDiagnostics(): String { + return object: AndroidTargetConfigurator(), ModuleConfiguratorWithTests, AndroidModuleConfigurator { + + override fun getConfiguratorSettings(): String { + return super.getConfiguratorSettings() + } + + inline fun anonymousInline() { + super.classFun() + super<ModuleConfiguratorWithTests>.getConfiguratorSettings() + super<AndroidModuleConfigurator>.getConfiguratorSettings() + } + + fun run() = super.classFun() + super<ModuleConfiguratorWithTests>.getConfiguratorSettings() + super<AndroidModuleConfigurator>.getConfiguratorSettings() + }.run() + } + + + + internal inline fun inlineInternal(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + private inline fun inlinePrivate(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + + //non-inline + override fun getConfiguratorSettings() = + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + + fun noInline() { + { + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + }() + + object { + fun run() = super@AndroidTargetConfigurator.classFun() + super@AndroidTargetConfigurator.getConfiguratorSettings() + super@AndroidTargetConfigurator.getConfiguratorSettings() + }.run() + } + +} + +open class Base { + fun classFun(): String = "Class" +} + +interface ModuleConfiguratorWithTests : ModuleConfiguratorWithSettings { + override fun getConfiguratorSettings() = "K" +} + +interface ModuleConfiguratorWithSettings { + fun getConfiguratorSettings(): String = "" +} + + +interface AndroidModuleConfigurator : + ModuleConfiguratorWithSettings { + override fun getConfiguratorSettings(): String { + return "O" + } +} + + +sealed class FooSealed : Base() { + class A : FooSealed() + + class B: FooSealed() + + inline fun test() { + super.classFun() + } + +} + +enum class FooEmum { + A, B { + + inline fun test() { + super.classFun() + } + }; + + fun classFun(): String = "Class" +} + +class FooOuter : Base() { + + inner class FooInner: Base() { + inline fun test() { + super@FooOuter.classFun() + super.classFun() + } + } + +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.kt b/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.kt new file mode 100644 index 00000000000..49b2b6a30d0 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.kt @@ -0,0 +1,123 @@ +// !LANGUAGE: -ProhibitSuperCallsFromPublicInline +// !DIAGNOSTICS: -EXPOSED_PARAMETER_TYPE -NOTHING_TO_INLINE + +// FILE: main.kt +open class AndroidTargetConfigurator : + Base(), + ModuleConfiguratorWithTests, + AndroidModuleConfigurator { + + public inline fun inlineFun(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + @PublishedApi + internal inline fun inlineFunPublished(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + public inline fun inlineFunAnonymousObjects(): String { + { + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + }() + + return object { + fun run() = super@AndroidTargetConfigurator.classFun() + super@AndroidTargetConfigurator.getConfiguratorSettings() + super@AndroidTargetConfigurator.getConfiguratorSettings() + }.run() + } + + public inline fun inlineFunAnonymousNoDiagnostics(): String { + return object: AndroidTargetConfigurator(), ModuleConfiguratorWithTests, AndroidModuleConfigurator { + + override fun getConfiguratorSettings(): String { + return super.getConfiguratorSettings() + } + + inline fun anonymousInline() { + super.classFun() + super<ModuleConfiguratorWithTests>.getConfiguratorSettings() + super<AndroidModuleConfigurator>.getConfiguratorSettings() + } + + fun run() = super.classFun() + super<ModuleConfiguratorWithTests>.getConfiguratorSettings() + super<AndroidModuleConfigurator>.getConfiguratorSettings() + }.run() + } + + + + internal inline fun inlineInternal(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + private inline fun inlinePrivate(): String { + return super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + } + + + //non-inline + override fun getConfiguratorSettings() = + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + + fun noInline() { + { + super.classFun() + super.getConfiguratorSettings() + super.getConfiguratorSettings() + }() + + object { + fun run() = super@AndroidTargetConfigurator.classFun() + super@AndroidTargetConfigurator.getConfiguratorSettings() + super@AndroidTargetConfigurator.getConfiguratorSettings() + }.run() + } + +} + +open class Base { + fun classFun(): String = "Class" +} + +interface ModuleConfiguratorWithTests : ModuleConfiguratorWithSettings { + override fun getConfiguratorSettings() = "K" +} + +interface ModuleConfiguratorWithSettings { + fun getConfiguratorSettings(): String = "" +} + + +interface AndroidModuleConfigurator : + ModuleConfiguratorWithSettings { + override fun getConfiguratorSettings(): String { + return "O" + } +} + + +sealed class FooSealed : Base() { + class A : FooSealed() + + class B: FooSealed() + + inline fun test() { + super.classFun() + } + +} + +enum class FooEmum { + A, B { + + inline fun test() { + super.classFun() + } + }; + + fun classFun(): String = "Class" +} + +class FooOuter : Base() { + + inner class FooInner: Base() { + inline fun test() { + super@FooOuter.classFun() + super.classFun() + } + } + +} diff --git a/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.txt b/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.txt new file mode 100644 index 00000000000..12419112d7c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.txt @@ -0,0 +1,112 @@ +package + +public interface AndroidModuleConfigurator : ModuleConfiguratorWithSettings { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun getConfiguratorSettings(): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class AndroidTargetConfigurator : Base, ModuleConfiguratorWithTests, AndroidModuleConfigurator { + public constructor AndroidTargetConfigurator() + public final override /*1*/ /*fake_override*/ fun classFun(): kotlin.String + public open override /*3*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ fun getConfiguratorSettings(): kotlin.String + public open override /*3*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final inline fun inlineFun(): kotlin.String + public final inline fun inlineFunAnonymousNoDiagnostics(): kotlin.String + public final inline fun inlineFunAnonymousObjects(): kotlin.String + @kotlin.PublishedApi internal final inline fun inlineFunPublished(): kotlin.String + internal final inline fun inlineInternal(): kotlin.String + private final inline fun inlinePrivate(): kotlin.String + public final fun noInline(): kotlin.Unit + public open override /*3*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Base { + public constructor Base() + public final fun classFun(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public final enum class FooEmum : kotlin.Enum { + enum entry A + + enum entry B + + private constructor FooEmum() + public final override /*1*/ /*fake_override*/ val name: kotlin.String + public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int + public final fun classFun(): kotlin.String + protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any + public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: FooEmum): kotlin.Int + public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit + public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class! + public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + // Static members + public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): FooEmum + public final /*synthesized*/ fun values(): kotlin.Array +} + +public final class FooOuter : Base { + public constructor FooOuter() + public final override /*1*/ /*fake_override*/ fun classFun(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final inner class FooInner : Base { + public constructor FooInner() + public final override /*1*/ /*fake_override*/ fun classFun(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final inline fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public sealed class FooSealed : Base { + protected constructor FooSealed() + public final override /*1*/ /*fake_override*/ fun classFun(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final inline fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public final class A : FooSealed { + public constructor A() + public final override /*1*/ /*fake_override*/ fun classFun(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ inline /*fake_override*/ fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public final class B : FooSealed { + public constructor B() + public final override /*1*/ /*fake_override*/ fun classFun(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final override /*1*/ inline /*fake_override*/ fun test(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} + +public interface ModuleConfiguratorWithSettings { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open fun getConfiguratorSettings(): kotlin.String + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface ModuleConfiguratorWithTests : ModuleConfiguratorWithSettings { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ fun getConfiguratorSettings(): kotlin.String + 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/inline/superCallFromMultipleSubclasses.fir.kt b/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.fir.kt new file mode 100644 index 00000000000..d8b02dcb9e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.fir.kt @@ -0,0 +1,27 @@ +// FILE: 1.kt + +package test + +open class A { + open fun test(s: String) = s +} + +object B : A() { + override fun test(s: String) = "fail" + + inline fun doTest(s: String) = super.test(s) +} + +object C : A() { + override fun test(s: String) = "fail" + + inline fun doTest(s: String) = super.test(s) +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return B.doTest("O") + C.doTest("K") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.kt b/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.kt new file mode 100644 index 00000000000..672913837b7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.kt @@ -0,0 +1,27 @@ +// FILE: 1.kt + +package test + +open class A { + open fun test(s: String) = s +} + +object B : A() { + override fun test(s: String) = "fail" + + inline fun doTest(s: String) = super.test(s) +} + +object C : A() { + override fun test(s: String) = "fail" + + inline fun doTest(s: String) = super.test(s) +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return B.doTest("O") + C.doTest("K") +} diff --git a/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.txt b/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.txt new file mode 100644 index 00000000000..018f9590151 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.txt @@ -0,0 +1,32 @@ +package + +public fun box(): kotlin.String + +package test { + + public open class A { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open fun test(/*0*/ s: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public object B : test.A { + private constructor B() + public final inline fun doTest(/*0*/ s: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(/*0*/ s: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public object C : test.A { + private constructor C() + public final inline fun doTest(/*0*/ s: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ fun test(/*0*/ s: kotlin.String): kotlin.String + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/tests/inline/superProperty.fir.kt b/compiler/testData/diagnostics/tests/inline/superProperty.fir.kt new file mode 100644 index 00000000000..d7c101ac11f --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superProperty.fir.kt @@ -0,0 +1,24 @@ +// FILE: 1.kt + +package test + +open class A { + open val test = "OK" +} + +object X : A() { + override val test: String + get() = "fail" + + inline fun doTest(): String { + return super.test + } +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return X.doTest() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/superProperty.kt b/compiler/testData/diagnostics/tests/inline/superProperty.kt new file mode 100644 index 00000000000..bbee94cb4cb --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superProperty.kt @@ -0,0 +1,24 @@ +// FILE: 1.kt + +package test + +open class A { + open val test = "OK" +} + +object X : A() { + override val test: String + get() = "fail" + + inline fun doTest(): String { + return super.test + } +} + +// FILE: 2.kt + +import test.* + +fun box(): String { + return X.doTest() +} diff --git a/compiler/testData/diagnostics/tests/inline/superProperty.txt b/compiler/testData/diagnostics/tests/inline/superProperty.txt new file mode 100644 index 00000000000..697939c7ae1 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/superProperty.txt @@ -0,0 +1,23 @@ +package + +public fun box(): kotlin.String + +package test { + + public open class A { + public constructor A() + public open val test: kotlin.String = "OK" + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public object X : test.A { + private constructor X() + public open override /*1*/ val test: kotlin.String + public final inline fun doTest(): kotlin.String + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + 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 8e777ff2ed8..de5fbcaf4e4 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 @@ -15927,12 +15927,36 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inline/stringTemplate.kt"); } + @Test + @TestMetadata("superCall.kt") + public void testSuperCall() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCall.kt"); + } + @Test @TestMetadata("superCallDepecation.kt") public void testSuperCallDepecation() throws Exception { runTest("compiler/testData/diagnostics/tests/inline/superCallDepecation.kt"); } + @Test + @TestMetadata("superCallDepecationWarning.kt") + public void testSuperCallDepecationWarning() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCallDepecationWarning.kt"); + } + + @Test + @TestMetadata("superCallFromMultipleSubclasses.kt") + public void testSuperCallFromMultipleSubclasses() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superCallFromMultipleSubclasses.kt"); + } + + @Test + @TestMetadata("superProperty.kt") + public void testSuperProperty() throws Exception { + runTest("compiler/testData/diagnostics/tests/inline/superProperty.kt"); + } + @Test @TestMetadata("unsupportedConstruction.kt") public void testUnsupportedConstruction() throws Exception { diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index d6475df783a..132e960469b 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -214,6 +214,7 @@ enum class LanguageFeature( RepeatableAnnotationContainerConstraints(KOTLIN_1_6, kind = BUG_FIX), UseBuilderInferenceOnlyIfNeeded(KOTLIN_1_6), SuspendConversion(KOTLIN_1_6), + ProhibitSuperCallsFromPublicInline(KOTLIN_1_6), // 1.7