[IR] Forbid MFVC primary constructors default arguments
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com> #KT-1179
This commit is contained in:
committed by
Space Team
parent
c6e54e6433
commit
adee33d3e5
@@ -420,6 +420,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> VALUE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION = DiagnosticFactory0.create(ERROR);
|
||||
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);
|
||||
|
||||
+1
@@ -795,6 +795,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(VALUE_CLASS_CANNOT_IMPLEMENT_INTERFACE_BY_DELEGATION, "Value class cannot implement an interface by delegation if expression is not a parameter");
|
||||
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");
|
||||
|
||||
@@ -26,11 +26,11 @@ private val DEFAULT_DECLARATION_CHECKERS = listOf(
|
||||
DelegationChecker(),
|
||||
KClassWithIncorrectTypeArgumentChecker,
|
||||
SuspendLimitationsChecker,
|
||||
InlineClassDeclarationChecker,
|
||||
PropertiesWithBackingFieldsInsideInlineClass(),
|
||||
InnerClassInsideInlineClass(),
|
||||
ValueClassDeclarationChecker,
|
||||
PropertiesWithBackingFieldsInsideValueClass(),
|
||||
InnerClassInsideValueClass(),
|
||||
AnnotationClassTargetAndRetentionChecker(),
|
||||
ReservedMembersAndConstructsForInlineClass(),
|
||||
ReservedMembersAndConstructsForValueClass(),
|
||||
ResultClassInReturnTypeChecker(),
|
||||
LocalVariableTypeParametersChecker(),
|
||||
ExplicitApiDeclarationChecker(),
|
||||
|
||||
+8
-3
@@ -127,6 +127,11 @@ object ValueClassDeclarationChecker : DeclarationChecker {
|
||||
baseParametersOk = false
|
||||
continue
|
||||
}
|
||||
|
||||
if (descriptor.isMultiFieldValueClass() && baseParameter.defaultValue != null) {
|
||||
// todo fix when inline arguments are supported
|
||||
trace.report(Errors.MULTI_FIELD_VALUE_CLASS_PRIMARY_CONSTRUCTOR_DEFAULT_PARAMETER.on(baseParameter.defaultValue!!))
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!baseParametersOk) {
|
||||
@@ -203,7 +208,7 @@ object ValueClassDeclarationChecker : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class PropertiesWithBackingFieldsInsideInlineClass : DeclarationChecker {
|
||||
class PropertiesWithBackingFieldsInsideValueClass : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (declaration !is KtProperty) return
|
||||
if (descriptor !is PropertyDescriptor) return
|
||||
@@ -220,7 +225,7 @@ class PropertiesWithBackingFieldsInsideInlineClass : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class InnerClassInsideInlineClass : DeclarationChecker {
|
||||
class InnerClassInsideValueClass : DeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||
if (declaration !is KtClass) return
|
||||
if (descriptor !is ClassDescriptor) return
|
||||
@@ -232,7 +237,7 @@ class InnerClassInsideInlineClass : DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
class ReservedMembersAndConstructsForInlineClass : DeclarationChecker {
|
||||
class ReservedMembersAndConstructsForValueClass : DeclarationChecker {
|
||||
|
||||
companion object {
|
||||
private val boxAndUnboxNames = setOf("box", "unbox")
|
||||
Reference in New Issue
Block a user