From e6d5df18b81310a661ef330738590649e276a61d Mon Sep 17 00:00:00 2001 From: Stanislav Ruban Date: Mon, 22 May 2023 17:31:37 +0300 Subject: [PATCH] [tests] Add new (and refactor existing) tests for @SubclassOptInRequired KT-54617 --- ...CompilerTestFE10TestdataTestGenerated.java | 88 +++++++-- ...sticCompilerFE10TestDataTestGenerated.java | 88 +++++++-- ...eeOldFrontendDiagnosticsTestGenerated.java | 88 +++++++-- ...siOldFrontendDiagnosticsTestGenerated.java | 88 +++++++-- .../CorrectApplicability.kt | 32 ++++ .../IncorrectApplicability.kt | 99 ++++++++++ .../InheritingByLocalClassifiers.kt | 31 ++++ .../InheritingDifferentOptInLevels.kt | 18 ++ .../NotApiMarkerAsArgument.kt | 6 + .../UsageOptInIsNotImplied.kt | 22 +++ .../WithAbstractClasses.kt | 34 ++++ .../WithInheritanceByDelegation.kt | 12 ++ .../subclassOptInRequired/WithInterfaces.kt | 34 ++++ .../subclassOptInRequired/WithOpenClasses.kt | 34 ++++ .../experimental/subClassOptInModality.kt | 102 ----------- .../experimental/subClassOptInModality.txt | 169 ------------------ .../experimental/subClassOptInRequired.kt | 51 ------ .../experimental/subClassOptInRequired.txt | 108 ----------- .../experimental/subclassOptInInheritance.kt | 64 ------- .../experimental/subclassOptInInheritance.txt | 68 ------- .../test/runners/DiagnosticTestGenerated.java | 88 +++++++-- 21 files changed, 672 insertions(+), 652 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.txt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.txt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt delete mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 37c11ff0e21..a4bc338e28e 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -37025,6 +37025,76 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired") + @TestDataPath("$PROJECT_ROOT") + public class SubclassOptInRequired { + @Test + public void testAllFilesPresentInSubclassOptInRequired() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("CorrectApplicability.kt") + public void testCorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt"); + } + + @Test + @TestMetadata("IncorrectApplicability.kt") + public void testIncorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt"); + } + + @Test + @TestMetadata("InheritingByLocalClassifiers.kt") + public void testInheritingByLocalClassifiers() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt"); + } + + @Test + @TestMetadata("InheritingDifferentOptInLevels.kt") + public void testInheritingDifferentOptInLevels() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt"); + } + + @Test + @TestMetadata("NotApiMarkerAsArgument.kt") + public void testNotApiMarkerAsArgument() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt"); + } + + @Test + @TestMetadata("UsageOptInIsNotImplied.kt") + public void testUsageOptInIsNotImplied() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt"); + } + + @Test + @TestMetadata("WithAbstractClasses.kt") + public void testWithAbstractClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt"); + } + + @Test + @TestMetadata("WithInheritanceByDelegation.kt") + public void testWithInheritanceByDelegation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt"); + } + + @Test + @TestMetadata("WithInterfaces.kt") + public void testWithInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt"); + } + + @Test + @TestMetadata("WithOpenClasses.kt") + public void testWithOpenClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt"); + } + } } @Nested @@ -39242,24 +39312,6 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt"); } - @Test - @TestMetadata("subClassOptInModality.kt") - public void testSubClassOptInModality() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt"); - } - - @Test - @TestMetadata("subClassOptInRequired.kt") - public void testSubClassOptInRequired() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt"); - } - - @Test - @TestMetadata("subclassOptInInheritance.kt") - public void testSubclassOptInInheritance() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt"); - } - @Test @TestMetadata("topLevel.kt") public void testTopLevel() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index b4df0ff4986..7a08d5d5850 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -37025,6 +37025,76 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired") + @TestDataPath("$PROJECT_ROOT") + public class SubclassOptInRequired { + @Test + public void testAllFilesPresentInSubclassOptInRequired() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("CorrectApplicability.kt") + public void testCorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt"); + } + + @Test + @TestMetadata("IncorrectApplicability.kt") + public void testIncorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt"); + } + + @Test + @TestMetadata("InheritingByLocalClassifiers.kt") + public void testInheritingByLocalClassifiers() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt"); + } + + @Test + @TestMetadata("InheritingDifferentOptInLevels.kt") + public void testInheritingDifferentOptInLevels() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt"); + } + + @Test + @TestMetadata("NotApiMarkerAsArgument.kt") + public void testNotApiMarkerAsArgument() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt"); + } + + @Test + @TestMetadata("UsageOptInIsNotImplied.kt") + public void testUsageOptInIsNotImplied() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt"); + } + + @Test + @TestMetadata("WithAbstractClasses.kt") + public void testWithAbstractClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt"); + } + + @Test + @TestMetadata("WithInheritanceByDelegation.kt") + public void testWithInheritanceByDelegation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt"); + } + + @Test + @TestMetadata("WithInterfaces.kt") + public void testWithInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt"); + } + + @Test + @TestMetadata("WithOpenClasses.kt") + public void testWithOpenClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt"); + } + } } @Nested @@ -39242,24 +39312,6 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt"); } - @Test - @TestMetadata("subClassOptInModality.kt") - public void testSubClassOptInModality() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt"); - } - - @Test - @TestMetadata("subClassOptInRequired.kt") - public void testSubClassOptInRequired() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt"); - } - - @Test - @TestMetadata("subclassOptInInheritance.kt") - public void testSubclassOptInInheritance() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt"); - } - @Test @TestMetadata("topLevel.kt") public void testTopLevel() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index aa821efd015..62eb9183261 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -37025,6 +37025,76 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired") + @TestDataPath("$PROJECT_ROOT") + public class SubclassOptInRequired { + @Test + public void testAllFilesPresentInSubclassOptInRequired() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("CorrectApplicability.kt") + public void testCorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt"); + } + + @Test + @TestMetadata("IncorrectApplicability.kt") + public void testIncorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt"); + } + + @Test + @TestMetadata("InheritingByLocalClassifiers.kt") + public void testInheritingByLocalClassifiers() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt"); + } + + @Test + @TestMetadata("InheritingDifferentOptInLevels.kt") + public void testInheritingDifferentOptInLevels() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt"); + } + + @Test + @TestMetadata("NotApiMarkerAsArgument.kt") + public void testNotApiMarkerAsArgument() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt"); + } + + @Test + @TestMetadata("UsageOptInIsNotImplied.kt") + public void testUsageOptInIsNotImplied() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt"); + } + + @Test + @TestMetadata("WithAbstractClasses.kt") + public void testWithAbstractClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt"); + } + + @Test + @TestMetadata("WithInheritanceByDelegation.kt") + public void testWithInheritanceByDelegation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt"); + } + + @Test + @TestMetadata("WithInterfaces.kt") + public void testWithInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt"); + } + + @Test + @TestMetadata("WithOpenClasses.kt") + public void testWithOpenClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt"); + } + } } @Nested @@ -39242,24 +39312,6 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt"); } - @Test - @TestMetadata("subClassOptInModality.kt") - public void testSubClassOptInModality() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt"); - } - - @Test - @TestMetadata("subClassOptInRequired.kt") - public void testSubClassOptInRequired() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt"); - } - - @Test - @TestMetadata("subclassOptInInheritance.kt") - public void testSubclassOptInInheritance() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt"); - } - @Test @TestMetadata("topLevel.kt") public void testTopLevel() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 3d968e30d7c..1787ca80a56 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -37121,6 +37121,76 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired") + @TestDataPath("$PROJECT_ROOT") + public class SubclassOptInRequired { + @Test + public void testAllFilesPresentInSubclassOptInRequired() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("CorrectApplicability.kt") + public void testCorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt"); + } + + @Test + @TestMetadata("IncorrectApplicability.kt") + public void testIncorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt"); + } + + @Test + @TestMetadata("InheritingByLocalClassifiers.kt") + public void testInheritingByLocalClassifiers() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt"); + } + + @Test + @TestMetadata("InheritingDifferentOptInLevels.kt") + public void testInheritingDifferentOptInLevels() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt"); + } + + @Test + @TestMetadata("NotApiMarkerAsArgument.kt") + public void testNotApiMarkerAsArgument() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt"); + } + + @Test + @TestMetadata("UsageOptInIsNotImplied.kt") + public void testUsageOptInIsNotImplied() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt"); + } + + @Test + @TestMetadata("WithAbstractClasses.kt") + public void testWithAbstractClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt"); + } + + @Test + @TestMetadata("WithInheritanceByDelegation.kt") + public void testWithInheritanceByDelegation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt"); + } + + @Test + @TestMetadata("WithInterfaces.kt") + public void testWithInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt"); + } + + @Test + @TestMetadata("WithOpenClasses.kt") + public void testWithOpenClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt"); + } + } } @Nested @@ -39338,24 +39408,6 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt"); } - @Test - @TestMetadata("subClassOptInModality.kt") - public void testSubClassOptInModality() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt"); - } - - @Test - @TestMetadata("subClassOptInRequired.kt") - public void testSubClassOptInRequired() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt"); - } - - @Test - @TestMetadata("subclassOptInInheritance.kt") - public void testSubclassOptInInheritance() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt"); - } - @Test @TestMetadata("topLevel.kt") public void testTopLevel() throws Exception { diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt new file mode 100644 index 00000000000..dabef7f38e8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt @@ -0,0 +1,32 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@SubclassOptInRequired(ApiMarker::class) +open class OpenKlass + +@SubclassOptInRequired(ApiMarker::class) +abstract class AbstractKlass + +@SubclassOptInRequired(ApiMarker::class) +interface Interface + +class OuterKlass { + + @SubclassOptInRequired(ApiMarker::class) + open class NestedOpenKlass + + @SubclassOptInRequired(ApiMarker::class) + abstract class NestedAbstractKlass + + @SubclassOptInRequired(ApiMarker::class) + interface NestedInterface + + @SubclassOptInRequired(ApiMarker::class) + open inner class InnerOpenKlass + + @SubclassOptInRequired(ApiMarker::class) + abstract inner class InnerAbstractKlass + +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt new file mode 100644 index 00000000000..37cd477d4f1 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt @@ -0,0 +1,99 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +// final classes are not valid targets for @SubclassOptInRequired + +@SubclassOptInRequired(ApiMarker::class) +class Klass + +@SubclassOptInRequired(ApiMarker::class) +data class DataKlass(val arg: Int) + +@SubclassOptInRequired(ApiMarker::class) +@JvmInline value class ValueKlass(val arg: Int) + +@SubclassOptInRequired(ApiMarker::class) +annotation class AnnotationKlass + +// functional interface is not a valid target for @SubclassOptInRequired + +@SubclassOptInRequired(ApiMarker::class) +fun interface FunctionalInterface { fun func() } + +// enum classes and objects are not valid targets for @SubclassOptInRequired + +@SubclassOptInRequired(ApiMarker::class) +enum class EnumKlass { ENTRY } + +@SubclassOptInRequired(ApiMarker::class) +object Objekt + +// sealed classifiers are not valid targets for @SubclassOptInRequired + +@SubclassOptInRequired(ApiMarker::class) +sealed class SealedKlass + +@SubclassOptInRequired(ApiMarker::class) +sealed interface SealedInterface + +// local classes are not valid targets for @SubclassOptInRequired + +fun foo() { + @SubclassOptInRequired(ApiMarker::class) + open class LocalOpenKlass + @SubclassOptInRequired(ApiMarker::class) + abstract class LocalAbstractKlass + @SubclassOptInRequired(ApiMarker::class) + class LocalKlass + @SubclassOptInRequired(ApiMarker::class) + data class LocalDataKlass(val arg: Int) + @SubclassOptInRequired(ApiMarker::class) + object {} +} + +class OuterKlass { + + // final classes are not valid targets for @SubclassOptInRequired + + @SubclassOptInRequired(ApiMarker::class) + class NestedKlass + + @SubclassOptInRequired(ApiMarker::class) + inner class InnerKlass + + @SubclassOptInRequired(ApiMarker::class) + data class NestedDataKlass(val arg: Int) + + @SubclassOptInRequired(ApiMarker::class) + @JvmInline value class NestedValueKlass(val arg: Int) + + @SubclassOptInRequired(ApiMarker::class) + annotation class NestedAnnotationKlass + + // functional interface is not a valid target for @SubclassOptInRequired + + @SubclassOptInRequired(ApiMarker::class) + fun interface NestedFunctionalInterface { fun func() } + + // enum classes and objects are not valid targets for @SubclassOptInRequired + + @SubclassOptInRequired(ApiMarker::class) + enum class NestedEnumKlass { ENTRY } + + @SubclassOptInRequired(ApiMarker::class) + object NestedObjekt + + @SubclassOptInRequired(ApiMarker::class) + companion object + + // sealed classifiers are not valid targets for @SubclassOptInRequired + + @SubclassOptInRequired(ApiMarker::class) + sealed class NestedSealedKlass + + @SubclassOptInRequired(ApiMarker::class) + sealed interface NestedSealedInterface + +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt new file mode 100644 index 00000000000..8a2c263dd15 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt @@ -0,0 +1,31 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@SubclassOptInRequired(ApiMarker::class) +interface Interface + +fun foo() { + // error: inheriting Interface requires an explicit opt-in + open class LocalOpenKlassA: Interface + abstract class LocalAbstractKlassA: Interface + class LocalKlassA: Interface + data class LocalDataKlassA(val arg: Int): Interface + object: Interface {} + + // opt-in is present, no errors + @OptIn(ApiMarker::class) open class LocalOpenKlassB: Interface + @OptIn(ApiMarker::class) abstract class LocalAbstractKlassB: Interface + @OptIn(ApiMarker::class) class LocalKlassB: Interface + @OptIn(ApiMarker::class) data class LocalDataKlassB(val arg: Int): Interface + @OptIn(ApiMarker::class) object: Interface {} + + // requiring to opt-in into local classifiers works as well + // (even though it doesn't make that much sense) + @ApiMarker open class LocalOpenKlassC: Interface + @ApiMarker abstract class LocalAbstractKlassC: Interface + @ApiMarker class LocalKlassC: Interface + @ApiMarker data class LocalDataKlassC(val arg: Int): Interface + @ApiMarker object: Interface {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt new file mode 100644 index 00000000000..8a702d5e6ed --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt @@ -0,0 +1,18 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@ApiMarker +interface I1 + +@SubclassOptInRequired(ApiMarker::class) +interface I2 + +// SubclassOptInRequired can only fix the error from I2 +@SubclassOptInRequired(ApiMarker::class) +interface Impl1: I1, I2 + +// the order of I1 and I2 shouldn't matter +@SubclassOptInRequired(ApiMarker::class) +interface Impl2: I2, I1 diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt new file mode 100644 index 00000000000..c694cadcb87 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt @@ -0,0 +1,6 @@ +// FIR_IDENTICAL + +annotation class DummyAnnotation + +@SubclassOptInRequired(DummyAnnotation::class) +open class IncorrectSubclassOptInArgumentMarker diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt new file mode 100644 index 00000000000..feb4127bb3f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt @@ -0,0 +1,22 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@ApiMarker +class UnstableKlassApi + +open class UnstableFunctionApi { + @ApiMarker + open fun overridableFunction() {} +} + +@SubclassOptInRequired(ApiMarker::class) +open class NotFullyOptedIntoApiMarker: UnstableFunctionApi() { + init { + // usage is unstable, error is reported even despite SubclassOptInRequired + UnstableKlassApi() + } + // usage is unstable, error is reported even despite SubclassOptInRequired + override fun overridableFunction() {} +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt new file mode 100644 index 00000000000..ba2c9115b65 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt @@ -0,0 +1,34 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@SubclassOptInRequired(ApiMarker::class) +abstract class AbstractKlassOptInApi + +// no opt-in: diagnostic reported +abstract class AbstractKlassOptInApiInheritorA: AbstractKlassOptInApi() + +// opt-in present: no diagnostic, opt-in isn't propagated +@OptIn(ApiMarker::class) +abstract class AbstractKlassOptInApiInheritorB: AbstractKlassOptInApi() + +// inheritance opt-in required: no diagnostic, opt-in is propagated +@SubclassOptInRequired(ApiMarker::class) +abstract class AbstractKlassOptInApiInheritorC: AbstractKlassOptInApi() + +// full opt-in required: no diagnostic, stricter opt-in is propagated +@ApiMarker +abstract class AbstractKlassOptInApiInheritorD: AbstractKlassOptInApi() + +abstract class AbstractKlassOptInApiInheritorE: AbstractKlassOptInApiInheritorB() // inheritance opt-in isn't propagated +abstract class AbstractKlassOptInApiInheritorF: AbstractKlassOptInApiInheritorC() // inheritance opt-in is propagated +abstract class AbstractKlassOptInApiInheritorG: AbstractKlassOptInApiInheritorD() // inheritance opt-in is propagated + +fun useSiteTestAbstractClasses( + o: AbstractKlassOptInApi, // usage opt-in isn't required + b: AbstractKlassOptInApiInheritorB, // usage opt-in isn't required + c: AbstractKlassOptInApiInheritorC, // usage opt-in isn't required + d: AbstractKlassOptInApiInheritorD, // usage opt-in is required + e: AbstractKlassOptInApiInheritorE // usage opt-in isn't required +) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt new file mode 100644 index 00000000000..b647f92dcec --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt @@ -0,0 +1,12 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@SubclassOptInRequired(ApiMarker::class) +interface ToBeInheritedByDelegation + +open class InheritingByDelegationA(arg: ToBeInheritedByDelegation): ToBeInheritedByDelegation by arg + +@SubclassOptInRequired(ApiMarker::class) +open class InheritingByDelegationB(arg: ToBeInheritedByDelegation): ToBeInheritedByDelegation by arg diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt new file mode 100644 index 00000000000..df0a75ce708 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt @@ -0,0 +1,34 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@SubclassOptInRequired(ApiMarker::class) +interface InterfaceOptInApi + +// no opt-in: diagnostic reported +interface InterfaceOptInApiInheritorA: InterfaceOptInApi + +// opt-in present: no diagnostic, opt-in isn't propagated +@OptIn(ApiMarker::class) +interface InterfaceOptInApiInheritorB: InterfaceOptInApi + +// inheritance opt-in required: no diagnostic, opt-in is propagated +@SubclassOptInRequired(ApiMarker::class) +interface InterfaceOptInApiInheritorC: InterfaceOptInApi + +// full opt-in required: no diagnostic, stricter opt-in is propagated +@ApiMarker +interface InterfaceOptInApiInheritorD: InterfaceOptInApi + +interface InterfaceOptInApiInheritorE: InterfaceOptInApiInheritorB // inheritance opt-in isn't propagated +interface InterfaceOptInApiInheritorF: InterfaceOptInApiInheritorC // inheritance opt-in is propagated +interface InterfaceOptInApiInheritorG: InterfaceOptInApiInheritorD // inheritance opt-in is propagated + +fun useSiteTestInterfaces( + o: InterfaceOptInApi, // usage opt-in isn't required + b: InterfaceOptInApiInheritorB, // usage opt-in isn't required + c: InterfaceOptInApiInheritorC, // usage opt-in isn't required + d: InterfaceOptInApiInheritorD, // usage opt-in is required + e: InterfaceOptInApiInheritorE // usage opt-in isn't required +) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt new file mode 100644 index 00000000000..83e24e39511 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt @@ -0,0 +1,34 @@ +// FIR_IDENTICAL + +@RequiresOptIn +annotation class ApiMarker + +@SubclassOptInRequired(ApiMarker::class) +open class OpenKlassOptInApi + +// no opt-in: diagnostic reported +open class OpenKlassOptInApiInheritorA: OpenKlassOptInApi() + +// opt-in present: no diagnostic, opt-in isn't propagated +@OptIn(ApiMarker::class) +open class OpenKlassOptInApiInheritorB: OpenKlassOptInApi() + +// inheritance opt-in required: no diagnostic, opt-in is propagated +@SubclassOptInRequired(ApiMarker::class) +open class OpenKlassOptInApiInheritorC: OpenKlassOptInApi() + +// full opt-in required: no diagnostic, stricter opt-in is propagated +@ApiMarker +open class OpenKlassOptInApiInheritorD: OpenKlassOptInApi() + +open class OpenKlassOptInApiInheritorE: OpenKlassOptInApiInheritorB() // inheritance opt-in isn't propagated +open class OpenKlassOptInApiInheritorF: OpenKlassOptInApiInheritorC() // inheritance opt-in is propagated +open class OpenKlassOptInApiInheritorG: OpenKlassOptInApiInheritorD() // inheritance opt-in is propagated + +fun useSiteTestOpenClasses() { + OpenKlassOptInApi() // usage opt-in isn't required + OpenKlassOptInApiInheritorB() // usage opt-in isn't required + OpenKlassOptInApiInheritorC() // usage opt-in isn't required + OpenKlassOptInApiInheritorD() // usage opt-in is required + OpenKlassOptInApiInheritorE() // usage opt-in isn't required +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt deleted file mode 100644 index f133132c566..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt +++ /dev/null @@ -1,102 +0,0 @@ -// FIR_IDENTICAL -@RequiresOptIn -annotation class Marker - -// Error! -@SubclassOptInRequired(Marker::class) -class Final - -// Error! -@SubclassOptInRequired(Marker::class) -sealed class SealedClass { - @SubclassOptInRequired(Marker::class) - object O : SealedClass() -} - -// Error! -@SubclassOptInRequired(Marker::class) -sealed interface SealedInterface - -// Error! -@SubclassOptInRequired(Marker::class) -fun interface FunInterface { - fun doIt() -} - -sealed class Normal - -// Ok! -@SubclassOptInRequired(Marker::class) -open class NormalOpen : Normal() - -// Ok! -@SubclassOptInRequired(Marker::class) -abstract class NormalAbstract : Normal() - -// Error! -@SubclassOptInRequired(Marker::class) -sealed class ErrorSealed : Normal() - -// Error! -@SubclassOptInRequired(Marker::class) -class ErrorFinal : Normal() - -// Ok! -@SubclassOptInRequired(Marker::class) -abstract class Abstract - -// Error! Should be replaced with OptIn -@SubclassOptInRequired(Marker::class) -class Derived1 : Abstract() - -// Ok! -@OptIn(Marker::class) -class Derived2 : Abstract() - -// Error! -@SubclassOptInRequired(Marker::class) -object Obj - -// Error! -@SubclassOptInRequired(Marker::class) -enum class E1 { - FIRST; -} - -enum class E2 { - // Error! - @SubclassOptInRequired(Marker::class) - SECOND; -} - -// Error! -@SubclassOptInRequired(Marker::class) -annotation class A - -// Local stuff -fun foo() { - // Error! - val v = @SubclassOptInRequired(Marker::class) object : Any() { - - } - - // Error! - @SubclassOptInRequired(Marker::class) - open class OpenLocal - - // Ok! - @OptIn(Marker::class) - class DerivedLocal : OpenLocal() - - // Error! - @SubclassOptInRequired(Marker::class) - class Local -} - -// Common rules with OptIn - -annotation class Simple - -// Error! Opt-in marker required -@SubclassOptInRequired(Simple::class) -open class Some diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.txt b/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.txt deleted file mode 100644 index 66c9f11dadb..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.txt +++ /dev/null @@ -1,169 +0,0 @@ -package - -public fun foo(): kotlin.Unit - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public final annotation class A : kotlin.Annotation { - 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 override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public abstract class Abstract { - public constructor Abstract() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public final class Derived1 : Abstract { - public constructor Derived1() - 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 -} - -@kotlin.OptIn(markerClass = {Marker::class}) public final class Derived2 : Abstract { - public constructor Derived2() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public final enum class E1 : kotlin.Enum { - enum entry FIRST - - private constructor E1() - @kotlin.internal.IntrinsicConstEvaluation public final override /*1*/ /*fake_override*/ val name: kotlin.String - public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int - protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any - public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: E1): 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*/ val entries: kotlin.enums.EnumEntries - public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): E1 - public final /*synthesized*/ fun values(): kotlin.Array -} - -public final enum class E2 : kotlin.Enum { - @kotlin.SubclassOptInRequired(markerClass = Marker::class) enum entry SECOND - - private constructor E2() - @kotlin.internal.IntrinsicConstEvaluation public final override /*1*/ /*fake_override*/ val name: kotlin.String - public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int - protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any - public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: E2): 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*/ val entries: kotlin.enums.EnumEntries - public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): E2 - public final /*synthesized*/ fun values(): kotlin.Array -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public final class ErrorFinal : Normal { - public constructor ErrorFinal() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public sealed class ErrorSealed : Normal { - protected constructor ErrorSealed() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public final class Final { - public constructor Final() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public fun interface FunInterface { - public abstract fun doIt(): kotlin.Unit - 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 -} - -@kotlin.RequiresOptIn public final annotation class Marker : kotlin.Annotation { - public constructor Marker() - 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 sealed class Normal { - protected constructor Normal() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public abstract class NormalAbstract : Normal { - public constructor NormalAbstract() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public open class NormalOpen : Normal { - public constructor NormalOpen() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public object Obj { - private constructor Obj() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public sealed class SealedClass { - protected constructor SealedClass() - 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 - - @kotlin.SubclassOptInRequired(markerClass = Marker::class) public object O : SealedClass { - private constructor O() - 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 - } -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public sealed interface SealedInterface { - 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 annotation class Simple : kotlin.Annotation { - public constructor Simple() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Simple::class) public open class Some { - public constructor Some() - 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/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt deleted file mode 100644 index 0721c40f68a..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt +++ /dev/null @@ -1,51 +0,0 @@ -// FIR_IDENTICAL -@RequiresOptIn -annotation class Marker - -@SubclassOptInRequired(Marker::class) -open class Base - -@Marker -class DerivedFirst : Base() - -@OptIn(Marker::class) -class DerivedSecond : Base() - -@SubclassOptInRequired(Marker::class) -open class DerivedThird : Base() - -open class DerivedFourth : Base() - -class GrandDerivedThird : DerivedThird() - -// Question: should we have an error also here? -class GrandDerivedFourth : DerivedFourth() - -@Marker -open class Marked - -@SubclassOptInRequired(Marker::class) -open class DerivedMarked : Marked() - -fun test() { - val b = Base() - val d1 = DerivedFirst() - val d2 = DerivedSecond() - val d3 = DerivedThird() - val d4 = DerivedFourth() -} - -fun test2(b: Base, g: Generic) { - object : Base() {} -} - -open class Generic - -class DerivedGeneric : Generic() - -@SubclassOptInRequired(Marker::class) -interface BaseInterface - -interface DerivedInterface : BaseInterface - -class Delegated(val bi: BaseInterface) : BaseInterface by bi diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.txt b/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.txt deleted file mode 100644 index b4ed3fb898d..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.txt +++ /dev/null @@ -1,108 +0,0 @@ -package - -public fun test(): kotlin.Unit -public fun test2(/*0*/ b: Base, /*1*/ g: Generic): kotlin.Unit - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public open class Base { - public constructor Base() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public interface BaseInterface { - 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 class Delegated : BaseInterface { - public constructor Delegated(/*0*/ bi: BaseInterface) - public final val bi: BaseInterface - 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 -} - -@Marker public final class DerivedFirst : Base { - public constructor DerivedFirst() - 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 open class DerivedFourth : Base { - public constructor DerivedFourth() - 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 class DerivedGeneric : Generic { - public constructor DerivedGeneric() - 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 interface DerivedInterface : BaseInterface { - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public open class DerivedMarked : Marked { - public constructor DerivedMarked() - 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 -} - -@kotlin.OptIn(markerClass = {Marker::class}) public final class DerivedSecond : Base { - public constructor DerivedSecond() - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public open class DerivedThird : Base { - public constructor DerivedThird() - 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 open class Generic { - public constructor Generic() - 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 class GrandDerivedFourth : DerivedFourth { - public constructor GrandDerivedFourth() - 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 class GrandDerivedThird : DerivedThird { - public constructor GrandDerivedThird() - 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 -} - -@Marker public open class Marked { - public constructor Marked() - 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 -} - -@kotlin.RequiresOptIn public final annotation class Marker : kotlin.Annotation { - public constructor Marker() - 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/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt deleted file mode 100644 index 2405c5c0ec8..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt +++ /dev/null @@ -1,64 +0,0 @@ -// FIR_IDENTICAL -@RequiresOptIn -annotation class Marker - -@Marker -interface I1 - -@SubclassOptInRequired(Marker::class) -interface I2 - -// Should not be enough, and should not depend on the order of I1, I2 -@SubclassOptInRequired(Marker::class) -interface Impl1 : I1, I2 - -@SubclassOptInRequired(Marker::class) -interface Impl2 : I2, I1 - -@Marker -class C - -open class D { - @Marker - open fun bar() {} - - @Marker - open fun baz() {} -} - -@SubclassOptInRequired(Marker::class) -open class E : D() { - init { - val c = C() - D().bar() - } - - fun foo() { - val c = C() - bar() // Error is not needed here (already reported on 'fun bar' declaration) - baz() - } - - override fun bar() { - - } - - @Marker - override fun baz() { - - } -} - -@SubclassOptInRequired(Marker::class) -interface Foo { - fun foo() = Unit -} - -inline fun inlineFoo() { - object : Foo { } -} - -fun test() { - // call site - inlineFoo() -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.txt b/compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.txt deleted file mode 100644 index 314fd6694b2..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.txt +++ /dev/null @@ -1,68 +0,0 @@ -package - -public inline fun inlineFoo(): kotlin.Unit -public fun test(): kotlin.Unit - -@Marker public final class C { - public constructor C() - 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 open class D { - public constructor D() - @Marker public open fun bar(): kotlin.Unit - @Marker public open fun baz(): kotlin.Unit - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public open class E : D { - public constructor E() - public open override /*1*/ fun bar(): kotlin.Unit - @Marker public open override /*1*/ fun baz(): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public final fun foo(): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public interface Foo { - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open fun foo(): kotlin.Unit - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} - -@Marker public interface I1 { - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public interface I2 { - 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 -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public interface Impl1 : I1, I2 { - public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String -} - -@kotlin.SubclassOptInRequired(markerClass = Marker::class) public interface Impl2 : I2, I1 { - public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String -} - -@kotlin.RequiresOptIn public final annotation class Marker : kotlin.Annotation { - public constructor Marker() - 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 832783c9615..1c085239a6f 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 @@ -37893,6 +37893,76 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/prohibitPositionedArgument/withoutValue.kt"); } } + + @Nested + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired") + @TestDataPath("$PROJECT_ROOT") + public class SubclassOptInRequired { + @Test + public void testAllFilesPresentInSubclassOptInRequired() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true); + } + + @Test + @TestMetadata("CorrectApplicability.kt") + public void testCorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/CorrectApplicability.kt"); + } + + @Test + @TestMetadata("IncorrectApplicability.kt") + public void testIncorrectApplicability() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/IncorrectApplicability.kt"); + } + + @Test + @TestMetadata("InheritingByLocalClassifiers.kt") + public void testInheritingByLocalClassifiers() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingByLocalClassifiers.kt"); + } + + @Test + @TestMetadata("InheritingDifferentOptInLevels.kt") + public void testInheritingDifferentOptInLevels() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/InheritingDifferentOptInLevels.kt"); + } + + @Test + @TestMetadata("NotApiMarkerAsArgument.kt") + public void testNotApiMarkerAsArgument() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/NotApiMarkerAsArgument.kt"); + } + + @Test + @TestMetadata("UsageOptInIsNotImplied.kt") + public void testUsageOptInIsNotImplied() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/UsageOptInIsNotImplied.kt"); + } + + @Test + @TestMetadata("WithAbstractClasses.kt") + public void testWithAbstractClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithAbstractClasses.kt"); + } + + @Test + @TestMetadata("WithInheritanceByDelegation.kt") + public void testWithInheritanceByDelegation() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInheritanceByDelegation.kt"); + } + + @Test + @TestMetadata("WithInterfaces.kt") + public void testWithInterfaces() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithInterfaces.kt"); + } + + @Test + @TestMetadata("WithOpenClasses.kt") + public void testWithOpenClasses() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/annotations/subclassOptInRequired/WithOpenClasses.kt"); + } + } } @Nested @@ -40110,24 +40180,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/overrideInPrimaryConstructor.kt"); } - @Test - @TestMetadata("subClassOptInModality.kt") - public void testSubClassOptInModality() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInModality.kt"); - } - - @Test - @TestMetadata("subClassOptInRequired.kt") - public void testSubClassOptInRequired() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subClassOptInRequired.kt"); - } - - @Test - @TestMetadata("subclassOptInInheritance.kt") - public void testSubclassOptInInheritance() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/subclassOptInInheritance.kt"); - } - @Test @TestMetadata("topLevel.kt") public void testTopLevel() throws Exception {