From b92ce68f32ccddb65d6c26878f46215bc4f8d898 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 21 Nov 2022 13:57:11 +0100 Subject: [PATCH] K2 opt-in: restore marker annotation check for constructors --- ...CompilerTestFE10TestdataTestGenerated.java | 6 ++++ ...irOldFrontendDiagnosticsTestGenerated.java | 6 ++++ ...DiagnosticsWithLightTreeTestGenerated.java | 6 ++++ .../expression/FirOptInUsageBaseChecker.kt | 8 ++--- .../experimental/constructorCheck.kt | 23 +++++++++++++++ .../experimental/constructorCheck.txt | 29 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 ++++ 7 files changed, 79 insertions(+), 5 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.txt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 33172df71bd..884c70efef5 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -37874,6 +37874,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt"); } + @Test + @TestMetadata("constructorCheck.kt") + public void testConstructorCheck() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt"); + } + @Test @TestMetadata("deeplyNestedClass.kt") public void testDeeplyNestedClass() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 29fe2e91652..d74a933d70a 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 @@ -37874,6 +37874,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt"); } + @Test + @TestMetadata("constructorCheck.kt") + public void testConstructorCheck() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt"); + } + @Test @TestMetadata("deeplyNestedClass.kt") public void testDeeplyNestedClass() 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 23b04164418..be8eb949f02 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 @@ -37874,6 +37874,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt"); } + @Test + @TestMetadata("constructorCheck.kt") + public void testConstructorCheck() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt"); + } + @Test @TestMetadata("deeplyNestedClass.kt") public void testDeeplyNestedClass() throws Exception { diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt index 6d8693a57c7..df9d6bfcad6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirOptInUsageBaseChecker.kt @@ -154,7 +154,7 @@ object FirOptInUsageBaseChecker { context, result, visited, fromSetter = false, dispatchReceiverType = null, fromSupertype = false ) } else { - fir.loadOverridableSpecificExperimentalities(session, context, visited, result) + fir.loadOverridableSpecificExperimentalities(context, visited, result) } dispatchReceiverType?.addExperimentalities(context, result, visited) if (fromSetter && this is FirPropertySymbol) { @@ -176,9 +176,10 @@ object FirOptInUsageBaseChecker { is FirAnonymousObject -> { } } - fir.loadExperimentalitiesFromAnnotationTo(session, result, fromSupertype) } + fir.loadExperimentalitiesFromAnnotationTo(session, result, fromSupertype) + if (fir.getAnnotationByClassId(OptInNames.WAS_EXPERIMENTAL_CLASS_ID) != null) { val accessibility = fir.checkSinceKotlinVersionAccessibility(context) if (accessibility is FirSinceKotlinAccessibility.NotAccessibleButWasExperimental) { @@ -194,7 +195,6 @@ object FirOptInUsageBaseChecker { } private fun FirCallableDeclaration.loadOverridableSpecificExperimentalities( - session: FirSession, context: CheckerContext, visited: MutableSet, result: SmartSet @@ -207,8 +207,6 @@ object FirOptInUsageBaseChecker { it.returnTypeRef.coneType.addExperimentalities(context, result, visited) } } - - loadExperimentalitiesFromAnnotationTo(session, result, fromSupertype = false) } private fun ConeKotlinType?.addExperimentalities( diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt b/compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt new file mode 100644 index 00000000000..dcfc9bb69e3 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt @@ -0,0 +1,23 @@ +// FIR_IDENTICAL +@RequiresOptIn +annotation class Marker + +@Marker +class Some(val x: Int) + +class Other(val x: Int) { + @OptIn(Marker::class) + constructor(some: Some): this(some.x) + + @Marker + constructor(): this(42) + + @OptIn(Marker::class) + constructor(y: Long, some: Some? = null): this(some?.x ?: y.toInt()) +} + +fun test() { + val o1 = Other() + val o2 = Other(Some(0)) + val o3 = Other(444L) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.txt b/compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.txt new file mode 100644 index 00000000000..50d5840eaa8 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.txt @@ -0,0 +1,29 @@ +package + +public fun test(): kotlin.Unit + +@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 final class Other { + @Marker public constructor Other() + @kotlin.OptIn(markerClass = {Marker::class}) public constructor Other(/*0*/ some: Some) + public constructor Other(/*0*/ x: kotlin.Int) + @kotlin.OptIn(markerClass = {Marker::class}) public constructor Other(/*0*/ y: kotlin.Long, /*1*/ some: Some? = ...) + public final val x: kotlin.Int + 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 Some { + public constructor Some(/*0*/ x: kotlin.Int) + public final val x: kotlin.Int + 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 42108a02df0..336bcdb5742 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 @@ -37964,6 +37964,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constVal.kt"); } + @Test + @TestMetadata("constructorCheck.kt") + public void testConstructorCheck() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/experimental/constructorCheck.kt"); + } + @Test @TestMetadata("deeplyNestedClass.kt") public void testDeeplyNestedClass() throws Exception {