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 c88145810ca..eeed18fc37b 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 @@ -18356,6 +18356,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt"); } + @Test + @TestMetadata("reservedConstructorsBodyInKotlinPre19.kt") + public void testReservedConstructorsBodyInKotlinPre19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt"); + } + @Test @TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt") public void testReservedMembersAndConstructsInsideInlineClass() 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 37ee6b8f122..e4ba5a0c68f 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 @@ -18362,6 +18362,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt"); } + @Test + @TestMetadata("reservedConstructorsBodyInKotlinPre19.kt") + public void testReservedConstructorsBodyInKotlinPre19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt"); + } + @Test @TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt") public void testReservedMembersAndConstructsInsideInlineClass() 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 043b95ae2a1..41ea34f4734 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 @@ -18356,6 +18356,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt"); } + @Test + @TestMetadata("reservedConstructorsBodyInKotlinPre19.kt") + public void testReservedConstructorsBodyInKotlinPre19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt"); + } + @Test @TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt") public void testReservedMembersAndConstructsInsideInlineClass() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index a23a7f17ec4..6fd95c75f19 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -426,7 +426,6 @@ public interface Errors { DiagnosticFactory0 VALUE_CLASS_CANNOT_EXTEND_CLASSES = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 VALUE_CLASS_CANNOT_BE_RECURSIVE = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR); DiagnosticFactory1 RESERVED_MEMBER_INSIDE_VALUE_CLASS = DiagnosticFactory1.create(ERROR); DiagnosticFactory0 TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS = DiagnosticFactory0.create(ERROR); DiagnosticFactory0 INNER_CLASS_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 3224e89dc4e..6747ce578b3 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -806,7 +806,6 @@ public class DefaultErrorMessages { MAP.put(VALUE_CLASS_CANNOT_EXTEND_CLASSES, "Value class cannot extend classes"); MAP.put(VALUE_CLASS_CANNOT_BE_RECURSIVE, "Value class cannot be recursive"); MAP.put(MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER, "Default parameters are not supported in the primary constructor of a multi-field value class"); - MAP.put(SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS, "Secondary constructors with bodies are reserved for for future releases"); MAP.put(RESERVED_MEMBER_INSIDE_VALUE_CLASS, "Member with the name ''{0}'' is reserved for future releases", STRING); MAP.put(TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS, "Type arguments for typed value class equals must be only star projections"); MAP.put(INNER_CLASS_INSIDE_VALUE_CLASS, "Value class cannot have inner classes"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt index fb724a18bc3..82b7ef58b6e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt @@ -265,7 +265,12 @@ class ReservedMembersAndConstructsForValueClass : DeclarationChecker { val bodyExpression = secondaryConstructor.bodyExpression if (secondaryConstructor.hasBlockBody() && bodyExpression is KtBlockExpression) { val lBrace = bodyExpression.lBrace ?: return - context.trace.report(Errors.SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS.on(lBrace)) + context.trace.report( + Errors.UNSUPPORTED_FEATURE.on( + lBrace, + LanguageFeature.ValueClassesSecondaryConstructorWithBody to context.languageVersionSettings + ) + ) } } } diff --git a/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.fir.kt b/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.fir.kt new file mode 100644 index 00000000000..a3b5f6875a5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.fir.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -ValueClassesSecondaryConstructorWithBody +// WITH_STDLIB + +@JvmInline +value class Foo(val x: String) { + constructor(i: Int) : this(i.toString()) { + println(i) + } +} diff --git a/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt b/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt new file mode 100644 index 00000000000..11b23602adf --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -ValueClassesSecondaryConstructorWithBody +// WITH_STDLIB + +@JvmInline +value class Foo(val x: String) { + constructor(i: Int) : this(i.toString()) { + println(i) + } +} diff --git a/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.txt b/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.txt new file mode 100644 index 00000000000..e994a418c1e --- /dev/null +++ b/compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.txt @@ -0,0 +1,10 @@ +package + +@kotlin.jvm.JvmInline public final value class Foo { + public constructor Foo(/*0*/ i: kotlin.Int) + public constructor Foo(/*0*/ x: kotlin.String) + public final val x: kotlin.String + public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*synthesized*/ 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 445687689f3..359dab22af5 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 @@ -18362,6 +18362,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inlineClasses/reifiedGenericUnderlyingType.kt"); } + @Test + @TestMetadata("reservedConstructorsBodyInKotlinPre19.kt") + public void testReservedConstructorsBodyInKotlinPre19() throws Exception { + runTest("compiler/testData/diagnostics/tests/inlineClasses/reservedConstructorsBodyInKotlinPre19.kt"); + } + @Test @TestMetadata("reservedMembersAndConstructsInsideInlineClass.kt") public void testReservedMembersAndConstructsInsideInlineClass() throws Exception {