[FE] Prohibit expect external and expect tailrec
^KT-58536 Fixed
This commit is contained in:
committed by
Space Team
parent
e6d5df18b8
commit
439cc88525
@@ -790,6 +790,8 @@ public interface Errors {
|
||||
DiagnosticFactory0<PsiElement> EXPECTED_LATEINIT_PROPERTY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> EXPECTED_PRIVATE_DECLARATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> EXPECTED_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> EXPECTED_TAILREC_FUNCTION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtDelegatedSuperTypeEntry> IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtTypeAlias> ACTUAL_TYPE_ALIAS_NOT_TO_CLASS = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
+2
@@ -352,6 +352,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(EXPECTED_LATEINIT_PROPERTY, "Expected property cannot be lateinit");
|
||||
MAP.put(SUPERTYPE_INITIALIZED_IN_EXPECTED_CLASS, "Expected classes cannot initialize supertypes");
|
||||
MAP.put(EXPECTED_PRIVATE_DECLARATION, "Expected declaration cannot be private");
|
||||
MAP.put(EXPECTED_EXTERNAL_DECLARATION, "Expected declaration cannot be external");
|
||||
MAP.put(EXPECTED_TAILREC_FUNCTION, "Expected function cannot have 'tailrec' modifier");
|
||||
|
||||
MAP.put(IMPLEMENTATION_BY_DELEGATION_IN_EXPECT_CLASS, "Implementation by delegation in expected classes is prohibited");
|
||||
|
||||
|
||||
@@ -343,7 +343,7 @@ class DeclarationsChecker(
|
||||
|
||||
checkPrimaryConstructor(classOrObject, classDescriptor)
|
||||
|
||||
checkPrivateExpectedDeclaration(classOrObject, classDescriptor)
|
||||
checkExpectDeclarationModifiers(classOrObject, classDescriptor)
|
||||
}
|
||||
|
||||
private fun checkLocalAnnotation(classDescriptor: ClassDescriptor, classOrObject: KtClassOrObject) {
|
||||
@@ -618,14 +618,29 @@ class DeclarationsChecker(
|
||||
shadowedExtensionChecker.checkDeclaration(property, propertyDescriptor)
|
||||
checkPropertyTypeParametersAreUsedInReceiverType(propertyDescriptor)
|
||||
checkImplicitCallableType(property, propertyDescriptor)
|
||||
checkPrivateExpectedDeclaration(property, propertyDescriptor)
|
||||
checkExpectDeclarationModifiers(property, propertyDescriptor)
|
||||
checkBackingField(property)
|
||||
}
|
||||
|
||||
private fun checkPrivateExpectedDeclaration(declaration: KtDeclaration, descriptor: MemberDescriptor) {
|
||||
if (descriptor.isExpect && DescriptorVisibilities.isPrivate(descriptor.visibility)) {
|
||||
private fun checkExpectDeclarationModifiers(declaration: KtDeclaration, descriptor: MemberDescriptor) {
|
||||
if (!descriptor.isExpect) return
|
||||
|
||||
if (DescriptorVisibilities.isPrivate(descriptor.visibility)) {
|
||||
trace.report(EXPECTED_PRIVATE_DECLARATION.on(declaration.modifierList?.getModifier(KtTokens.PRIVATE_KEYWORD) ?: declaration))
|
||||
}
|
||||
|
||||
checkExpectDeclarationHasNoExternalModifier(declaration)
|
||||
if (declaration is KtFunction) {
|
||||
declaration.modifierList?.getModifier(KtTokens.TAILREC_KEYWORD)?.let {
|
||||
trace.report(EXPECTED_TAILREC_FUNCTION.on(it))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkExpectDeclarationHasNoExternalModifier(declaration: KtDeclaration) {
|
||||
declaration.modifierList?.getModifier(KtTokens.EXTERNAL_KEYWORD)?.let {
|
||||
trace.report(EXPECTED_EXTERNAL_DECLARATION.on(it))
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkPropertyTypeParametersAreUsedInReceiverType(descriptor: PropertyDescriptor) {
|
||||
@@ -925,7 +940,7 @@ class DeclarationsChecker(
|
||||
trace.report(EXPECTED_DECLARATION_WITH_BODY.on(function))
|
||||
}
|
||||
|
||||
checkPrivateExpectedDeclaration(function, functionDescriptor)
|
||||
checkExpectDeclarationModifiers(function, functionDescriptor)
|
||||
}
|
||||
|
||||
private fun checkActualFunction(element: KtDeclaration, functionDescriptor: FunctionDescriptor) {
|
||||
@@ -1022,6 +1037,9 @@ class DeclarationsChecker(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (propertyDescriptor.isExpect) {
|
||||
checkExpectDeclarationHasNoExternalModifier(accessor)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkEnumEntry(enumEntry: KtEnumEntry, enumEntryClass: ClassDescriptor) {
|
||||
|
||||
Reference in New Issue
Block a user