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
This commit is contained in:
Mikhail Zarechenskiy
2023-02-01 11:23:19 +01:00
committed by Space Team
parent f3e022e4ca
commit c586d7a03a
10 changed files with 58 additions and 3 deletions
@@ -426,7 +426,6 @@ public interface Errors {
DiagnosticFactory0<KtTypeReference> VALUE_CLASS_CANNOT_EXTEND_CLASSES = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtTypeReference> VALUE_CLASS_CANNOT_BE_RECURSIVE = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<KtExpression> MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory1<PsiElement, String> RESERVED_MEMBER_INSIDE_VALUE_CLASS = DiagnosticFactory1.create(ERROR);
DiagnosticFactory0<KtTypeReference> TYPE_ARGUMENT_ON_TYPED_VALUE_CLASS_EQUALS = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<PsiElement> INNER_CLASS_INSIDE_VALUE_CLASS = DiagnosticFactory0.create(ERROR);
@@ -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");
@@ -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
)
)
}
}
}