Reserve secondary constructors with bodies inside inline classes
#KT-26575 Fixed
This commit is contained in:
@@ -331,6 +331,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtTypeReference> INLINE_CLASS_CANNOT_EXTEND_CLASSES = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtTypeReference> INLINE_CLASS_CANNOT_BE_RECURSIVE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> RESERVED_MEMBER_INSIDE_INLINE_CLASS = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_INLINE_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Secondary constructors
|
||||
|
||||
|
||||
+1
@@ -662,6 +662,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(INLINE_CLASS_CANNOT_EXTEND_CLASSES, "Inline class cannot extend classes");
|
||||
MAP.put(INLINE_CLASS_CANNOT_BE_RECURSIVE, "Inline class cannot be recursive");
|
||||
MAP.put(RESERVED_MEMBER_INSIDE_INLINE_CLASS, "Member with the name ''{0}'' is reserved for future releases", STRING);
|
||||
MAP.put(SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_INLINE_CLASS, "Secondary constructors with bodies are reserved for for future releases");
|
||||
|
||||
MAP.put(VARIANCE_ON_TYPE_PARAMETER_NOT_ALLOWED, "Variance annotations are only allowed for type parameters of classes and interfaces");
|
||||
MAP.put(BOUND_ON_TYPE_ALIAS_PARAMETER_NOT_ALLOWED, "Bounds are not allowed on type alias parameters");
|
||||
|
||||
+19
-5
@@ -151,11 +151,25 @@ class ReservedMembersAndConstructsForInlineClass : DeclarationChecker {
|
||||
val containingDeclaration = descriptor.containingDeclaration ?: return
|
||||
if (!containingDeclaration.isInlineClass()) return
|
||||
|
||||
if (declaration is KtFunction && descriptor is FunctionDescriptor) {
|
||||
val functionName = descriptor.name.asString()
|
||||
if (functionName in reservedFunctions) {
|
||||
val nameIdentifier = declaration.nameIdentifier ?: return
|
||||
context.trace.report(Errors.RESERVED_MEMBER_INSIDE_INLINE_CLASS.on(nameIdentifier, functionName))
|
||||
if (descriptor !is FunctionDescriptor) return
|
||||
|
||||
when (descriptor) {
|
||||
is SimpleFunctionDescriptor -> {
|
||||
val ktFunction = declaration as? KtFunction ?: return
|
||||
val functionName = descriptor.name.asString()
|
||||
if (functionName in reservedFunctions) {
|
||||
val nameIdentifier = ktFunction.nameIdentifier ?: return
|
||||
context.trace.report(Errors.RESERVED_MEMBER_INSIDE_INLINE_CLASS.on(nameIdentifier, functionName))
|
||||
}
|
||||
}
|
||||
|
||||
is ConstructorDescriptor -> {
|
||||
val secondaryConstructor = declaration as? KtSecondaryConstructor ?: return
|
||||
val bodyExpression = secondaryConstructor.bodyExpression
|
||||
if (secondaryConstructor.hasBlockBody() && bodyExpression is KtBlockExpression) {
|
||||
val lBrace = bodyExpression.lBrace ?: return
|
||||
context.trace.report(Errors.SECONDARY_CONSTRUCTOR_WITH_BODY_INSIDE_INLINE_CLASS.on(lBrace))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user