Skip to content

Commit 9d488c6

Browse files
committed
Use more specific error for secondary constructor bodies in inline classes
- Also, this error allows IDE to provide quick-fix that changes language version in a project that simplifies the adoption - There is no point in changing K2 part as there this feature will be enabled by default ^KT-56224 Fixed
1 parent e09cd0b commit 9d488c6

File tree

12 files changed

+61
-6
lines changed

12 files changed

+61
-6
lines changed

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,6 @@ public interface Errors {
426426
DiagnosticFactory0<KtTypeReference> VALUE_CLASS_CANNOT_EXTEND_CLASSES = DiagnosticFactory0.create(ERROR);
427427
DiagnosticFactory0<KtTypeReference> VALUE_CLASS_CANNOT_BE_RECURSIVE = DiagnosticFactory0.create(ERROR);
428428
DiagnosticFactory0<KtExpression> MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR);
429-
DiagnosticFactory0<PsiElement> SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
430429
DiagnosticFactory1<PsiElement, String> RESERVED_MEMBER_INSIDE_VALUE_CLASS = DiagnosticFactory1.create(ERROR);
431430
DiagnosticFactory0<KtTypeReference> TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS = DiagnosticFactory0.create(ERROR);
432431
DiagnosticFactory0<PsiElement> INNER_CLASS_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);

compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,6 @@ public static DiagnosticRenderer getRendererForDiagnostic(@NotNull UnboundDiagno
806806
MAP.put(VALUE_CLASS_CANNOT_EXTEND_CLASSES, "Value class cannot extend classes");
807807
MAP.put(VALUE_CLASS_CANNOT_BE_RECURSIVE, "Value class cannot be recursive");
808808
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");
809-
MAP.put(SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS, "Secondary constructors with bodies are reserved for for future releases");
810809
MAP.put(RESERVED_MEMBER_INSIDE_VALUE_CLASS, "Member with the name ''{0}'' is reserved for future releases", STRING);
811810
MAP.put(TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS, "Type arguments for typed value class equals must be only star projections");
812811
MAP.put(INNER_CLASS_INSIDE_VALUE_CLASS, "Value class cannot have inner classes");

compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/ValueClassDeclarationChecker.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,12 @@ class ReservedMembersAndConstructsForValueClass : DeclarationChecker {
265265
val bodyExpression = secondaryConstructor.bodyExpression
266266
if (secondaryConstructor.hasBlockBody() && bodyExpression is KtBlockExpression) {
267267
val lBrace = bodyExpression.lBrace ?: return
268-
context.trace.report(Errors.SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS.on(lBrace))
268+
context.trace.report(
269+
Errors.UNSUPPORTED_FEATURE.on(
270+
lBrace,
271+
LanguageFeature.ValueClassesSecondaryConstructorWithBody to context.languageVersionSettings
272+
)
273+
)
269274
}
270275
}
271276
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// !LANGUAGE: -ValueClassesSecondaryConstructorWithBody
2+
// WITH_STDLIB
3+
4+
@JvmInline
5+
value class Foo(val x: String) {
6+
constructor(i: Int) : this(i.toString()) <!SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS!>{
7+
println(i)
8+
}<!>
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// !LANGUAGE: -ValueClassesSecondaryConstructorWithBody
2+
// WITH_STDLIB
3+
4+
@JvmInline
5+
value class Foo(val x: String) {
6+
constructor(i: Int) : this(i.toString()) <!UNSUPPORTED_FEATURE!>{<!>
7+
println(i)
8+
}
9+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package
2+
3+
@kotlin.jvm.JvmInline public final value class Foo {
4+
public constructor Foo(/*0*/ i: kotlin.Int)
5+
public constructor Foo(/*0*/ x: kotlin.String)
6+
public final val x: kotlin.String
7+
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
8+
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
9+
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
10+
}

compiler/testData/diagnostics/tests/inlineClasses/reservedMembersAndConstructsInsideInlineClass.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ value class IC4(val s: String) : WithBox {
4545

4646
@JvmInline
4747
value class IC5(val a: String) {
48-
constructor(i: Int) : this(i.toString()) <!SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS!>{<!>
48+
constructor(i: Int) : this(i.toString()) <!UNSUPPORTED_FEATURE!>{<!>
4949
TODO("something")
5050
}
5151
}

0 commit comments

Comments
 (0)