FIR checker: simplify isExpect|isExternal checks
Those resolve information are different from modality/visibility, which could have conflicting modifiers.
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
774ba58062
commit
9badbfc30d
+5
-10
@@ -36,22 +36,18 @@ private inline fun isInsideSpecificClass(
|
|||||||
|
|
||||||
internal fun FirMemberDeclaration.isEffectivelyExpect(
|
internal fun FirMemberDeclaration.isEffectivelyExpect(
|
||||||
containingClass: FirRegularClass?,
|
containingClass: FirRegularClass?,
|
||||||
modifierList: FirModifierList? = null,
|
|
||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val isExpect = this.isExpect || modifierList?.modifiers?.any { it.token == KtTokens.EXPECT_KEYWORD } == true
|
if (this.isExpect) return true
|
||||||
if (isExpect) return true
|
|
||||||
|
|
||||||
return containingClass != null && isInsideExpectClass(containingClass, context)
|
return containingClass != null && isInsideExpectClass(containingClass, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun FirMemberDeclaration.isEffectivelyExternal(
|
internal fun FirMemberDeclaration.isEffectivelyExternal(
|
||||||
containingClass: FirRegularClass?,
|
containingClass: FirRegularClass?,
|
||||||
modifierList: FirModifierList? = null,
|
|
||||||
context: CheckerContext,
|
context: CheckerContext,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
val isExternal = this.isExternal || modifierList?.modifiers?.any { it.token == KtTokens.EXTERNAL_KEYWORD } == true
|
if (this.isExternal) return true
|
||||||
if (isExternal) return true
|
|
||||||
|
|
||||||
// NB: [MemberDescriptor.isEffectivelyExternal] checks property accessors for property and vice versa.
|
// NB: [MemberDescriptor.isEffectivelyExternal] checks property accessors for property and vice versa.
|
||||||
// But, raw FIR creation already did such upward/downward propagation of modifiers.
|
// But, raw FIR creation already did such upward/downward propagation of modifiers.
|
||||||
@@ -63,11 +59,10 @@ internal fun FirMemberDeclaration.isEffectivelyExternal(
|
|||||||
internal fun checkExpectDeclarationVisibilityAndBody(
|
internal fun checkExpectDeclarationVisibilityAndBody(
|
||||||
declaration: FirMemberDeclaration,
|
declaration: FirMemberDeclaration,
|
||||||
source: FirSourceElement,
|
source: FirSourceElement,
|
||||||
modifierList: FirModifierList?,
|
|
||||||
reporter: DiagnosticReporter,
|
reporter: DiagnosticReporter,
|
||||||
context: CheckerContext
|
context: CheckerContext
|
||||||
) {
|
) {
|
||||||
if (declaration.isExpect || modifierList?.modifiers?.any { it.token == KtTokens.EXPECT_KEYWORD } == true) {
|
if (declaration.isExpect) {
|
||||||
if (Visibilities.isPrivate(declaration.visibility)) {
|
if (Visibilities.isPrivate(declaration.visibility)) {
|
||||||
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
|
reporter.reportOn(source, FirErrors.EXPECTED_PRIVATE_DECLARATION, context)
|
||||||
}
|
}
|
||||||
@@ -116,7 +111,7 @@ private fun checkPropertyInitializer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val isExpect = property.isEffectivelyExpect(containingClass, modifierList, context)
|
val isExpect = property.isEffectivelyExpect(containingClass, context)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
property.initializer != null -> {
|
property.initializer != null -> {
|
||||||
@@ -150,7 +145,7 @@ private fun checkPropertyInitializer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
val isExternal = property.isEffectivelyExternal(containingClass, modifierList, context)
|
val isExternal = property.isEffectivelyExternal(containingClass, context)
|
||||||
if (backingFieldRequired && !inInterface && !property.isLateInit && !isExpect && !isInitialized && !isExternal) {
|
if (backingFieldRequired && !inInterface && !property.isLateInit && !isExpect && !isInitialized && !isExternal) {
|
||||||
property.source?.let {
|
property.source?.let {
|
||||||
if (property.receiverTypeRef != null && !property.hasAccessorImplementation) {
|
if (property.receiverTypeRef != null && !property.hasAccessorImplementation) {
|
||||||
|
|||||||
+2
-3
@@ -50,7 +50,6 @@ object FirMemberFunctionsChecker : FirRegularClassChecker() {
|
|||||||
}
|
}
|
||||||
val isInsideExpectClass = isInsideExpectClass(containingDeclaration, context)
|
val isInsideExpectClass = isInsideExpectClass(containingDeclaration, context)
|
||||||
val hasOpenModifier = modifierList?.modifiers?.any { it.token == KtTokens.OPEN_KEYWORD } == true
|
val hasOpenModifier = modifierList?.modifiers?.any { it.token == KtTokens.OPEN_KEYWORD } == true
|
||||||
val isExternal = function.isExternal || modifierList?.modifiers?.any { it.token == KtTokens.EXTERNAL_KEYWORD } == true
|
|
||||||
if (!function.hasBody) {
|
if (!function.hasBody) {
|
||||||
if (containingDeclaration.isInterface) {
|
if (containingDeclaration.isInterface) {
|
||||||
if (Visibilities.isPrivate(function.visibility)) {
|
if (Visibilities.isPrivate(function.visibility)) {
|
||||||
@@ -59,11 +58,11 @@ object FirMemberFunctionsChecker : FirRegularClassChecker() {
|
|||||||
if (!isInsideExpectClass && !hasAbstractModifier && hasOpenModifier) {
|
if (!isInsideExpectClass && !hasAbstractModifier && hasOpenModifier) {
|
||||||
reporter.reportOn(source, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context)
|
reporter.reportOn(source, FirErrors.REDUNDANT_OPEN_IN_INTERFACE, context)
|
||||||
}
|
}
|
||||||
} else if (!isInsideExpectClass && !hasAbstractModifier && !isExternal) {
|
} else if (!isInsideExpectClass && !hasAbstractModifier && !function.isExternal) {
|
||||||
reporter.reportOn(source, FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, function, context)
|
reporter.reportOn(source, FirErrors.NON_ABSTRACT_FUNCTION_WITH_NO_BODY, function, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
checkExpectDeclarationVisibilityAndBody(function, source, modifierList, reporter, context)
|
checkExpectDeclarationVisibilityAndBody(function, source, reporter, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -149,7 +149,7 @@ object FirMemberPropertiesChecker : FirRegularClassChecker() {
|
|||||||
val modifierList = with(FirModifierList) { property.source.getModifierList() }
|
val modifierList = with(FirModifierList) { property.source.getModifierList() }
|
||||||
|
|
||||||
checkProperty(containingDeclaration, property, modifierList, isInitialized, reporter, context)
|
checkProperty(containingDeclaration, property, modifierList, isInitialized, reporter, context)
|
||||||
checkExpectDeclarationVisibilityAndBody(property, source, modifierList, reporter, context)
|
checkExpectDeclarationVisibilityAndBody(property, source, reporter, context)
|
||||||
|
|
||||||
val hasAbstractModifier = modifierList?.modifiers?.any { it.token == KtTokens.ABSTRACT_KEYWORD } == true
|
val hasAbstractModifier = modifierList?.modifiers?.any { it.token == KtTokens.ABSTRACT_KEYWORD } == true
|
||||||
val isAbstract = property.isAbstract || hasAbstractModifier
|
val isAbstract = property.isAbstract || hasAbstractModifier
|
||||||
|
|||||||
+3
-4
@@ -30,12 +30,11 @@ object FirTopLevelFunctionsChecker : FirFileChecker() {
|
|||||||
// So, our source of truth should be the full modifier list retrieved from the source.
|
// So, our source of truth should be the full modifier list retrieved from the source.
|
||||||
val modifierList = with(FirModifierList) { source.getModifierList() }
|
val modifierList = with(FirModifierList) { source.getModifierList() }
|
||||||
if (modifierList?.modifiers?.any { it.token == KtTokens.ABSTRACT_KEYWORD } == true) return
|
if (modifierList?.modifiers?.any { it.token == KtTokens.ABSTRACT_KEYWORD } == true) return
|
||||||
if (function.isExternal || modifierList?.modifiers?.any { it.token == KtTokens.EXTERNAL_KEYWORD } == true) return
|
if (function.isExternal) return
|
||||||
val isExpect = function.isExpect || modifierList?.modifiers?.any { it.token == KtTokens.EXPECT_KEYWORD } == true
|
if (!function.hasBody && !function.isExpect) {
|
||||||
if (!function.hasBody && !isExpect) {
|
|
||||||
reporter.reportOn(source, FirErrors.NON_MEMBER_FUNCTION_NO_BODY, function, context)
|
reporter.reportOn(source, FirErrors.NON_MEMBER_FUNCTION_NO_BODY, function, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
checkExpectDeclarationVisibilityAndBody(function, source, modifierList, reporter, context)
|
checkExpectDeclarationVisibilityAndBody(function, source, reporter, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -29,6 +29,6 @@ object FirTopLevelPropertiesChecker : FirFileChecker() {
|
|||||||
val modifierList = with(FirModifierList) { source.getModifierList() }
|
val modifierList = with(FirModifierList) { source.getModifierList() }
|
||||||
|
|
||||||
checkProperty(null, property, modifierList, property.initializer != null, reporter, context)
|
checkProperty(null, property, modifierList, property.initializer != null, reporter, context)
|
||||||
checkExpectDeclarationVisibilityAndBody(property, source, modifierList, reporter, context)
|
checkExpectDeclarationVisibilityAndBody(property, source, reporter, context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user