[FIR] Implement EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE
^KT-60367 Fixed KT review: https://jetbrains.team/p/kt/reviews/14064/timeline IJ review: https://jetbrains.team/p/ij/reviews/124657/timeline
This commit is contained in:
+3
@@ -1079,6 +1079,9 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
val PACKAGE_OR_CLASSIFIER_REDECLARATION by error<KtNamedDeclaration>(PositioningStrategy.ACTUAL_DECLARATION_NAME) {
|
||||
parameter<Collection<Symbol>>("conflictingDeclarations")
|
||||
}
|
||||
val EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE by error<KtNamedDeclaration>(PositioningStrategy.ACTUAL_DECLARATION_NAME) {
|
||||
parameter<Symbol>("declaration")
|
||||
}
|
||||
val METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE by error<PsiElement>()
|
||||
}
|
||||
|
||||
|
||||
@@ -552,6 +552,7 @@ object FirErrors {
|
||||
val CONFLICTING_OVERLOADS: KtDiagnosticFactory1<Collection<FirBasedSymbol<*>>> by error1<PsiElement, Collection<FirBasedSymbol<*>>>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
val REDECLARATION: KtDiagnosticFactory1<Collection<FirBasedSymbol<*>>> by error1<KtNamedDeclaration, Collection<FirBasedSymbol<*>>>(SourceElementPositioningStrategies.NAME_IDENTIFIER)
|
||||
val PACKAGE_OR_CLASSIFIER_REDECLARATION: KtDiagnosticFactory1<Collection<FirBasedSymbol<*>>> by error1<KtNamedDeclaration, Collection<FirBasedSymbol<*>>>(SourceElementPositioningStrategies.ACTUAL_DECLARATION_NAME)
|
||||
val EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE: KtDiagnosticFactory1<FirBasedSymbol<*>> by error1<KtNamedDeclaration, FirBasedSymbol<*>>(SourceElementPositioningStrategies.ACTUAL_DECLARATION_NAME)
|
||||
val METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE: KtDiagnosticFactory0 by error0<PsiElement>()
|
||||
|
||||
// Invalid local declarations
|
||||
|
||||
+1
@@ -361,6 +361,7 @@ val FIR_NON_SUPPRESSIBLE_ERROR_NAMES: Set<String> = setOf(
|
||||
"CONFLICTING_OVERLOADS",
|
||||
"REDECLARATION",
|
||||
"PACKAGE_OR_CLASSIFIER_REDECLARATION",
|
||||
"EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE",
|
||||
"METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE",
|
||||
"LOCAL_OBJECT_NOT_ALLOWED",
|
||||
"LOCAL_INTERFACE_NOT_ALLOWED",
|
||||
|
||||
+2
-2
@@ -93,7 +93,7 @@ private val FirBasedSymbol<*>.resolvedStatus
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun isExpectAndActual(declaration1: FirBasedSymbol<*>, declaration2: FirBasedSymbol<*>): Boolean {
|
||||
internal fun isExpectAndActual(declaration1: FirBasedSymbol<*>, declaration2: FirBasedSymbol<*>): Boolean {
|
||||
val status1 = declaration1.resolvedStatus ?: return false
|
||||
val status2 = declaration2.resolvedStatus ?: return false
|
||||
return (status1.isExpect && status2.isActual) || (status1.isActual && status2.isExpect)
|
||||
@@ -496,7 +496,7 @@ private fun FirDeclarationCollector<*>.areNonConflictingCallables(
|
||||
declaration: FirBasedSymbol<*>,
|
||||
conflicting: FirBasedSymbol<*>,
|
||||
): Boolean {
|
||||
if (isExpectAndActual(declaration, conflicting)) return true
|
||||
if (isExpectAndActual(declaration, conflicting) && declaration.moduleData != conflicting.moduleData) return true
|
||||
|
||||
val declarationIsLowPriority = hasLowPriorityAnnotation(declaration.annotations)
|
||||
val conflictingIsLowPriority = hasLowPriorityAnnotation(conflicting.annotations)
|
||||
|
||||
+15
-12
@@ -90,19 +90,22 @@ object FirConflictsDeclarationChecker : FirBasicDeclarationChecker(MppCheckerKin
|
||||
conflictingDeclaration.isPrimaryConstructor && symbols.all { it.isPrimaryConstructor }
|
||||
) return@forEach
|
||||
|
||||
val factory =
|
||||
if (conflictingDeclaration is FirNamedFunctionSymbol || conflictingDeclaration is FirConstructorSymbol) {
|
||||
FirErrors.CONFLICTING_OVERLOADS
|
||||
} else if (conflictingDeclaration is FirClassLikeSymbol<*> &&
|
||||
conflictingDeclaration.getContainingClassSymbol(context.session) == null &&
|
||||
symbols.any { it is FirClassLikeSymbol<*> }
|
||||
) {
|
||||
FirErrors.PACKAGE_OR_CLASSIFIER_REDECLARATION
|
||||
} else {
|
||||
FirErrors.REDECLARATION
|
||||
when {
|
||||
symbols.singleOrNull()?.let { isExpectAndActual(conflictingDeclaration, it) } == true -> {
|
||||
reporter.reportOn(source, FirErrors.EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE, conflictingDeclaration, context)
|
||||
}
|
||||
|
||||
reporter.reportOn(source, factory, symbols, context)
|
||||
conflictingDeclaration is FirNamedFunctionSymbol || conflictingDeclaration is FirConstructorSymbol -> {
|
||||
reporter.reportOn(source, FirErrors.CONFLICTING_OVERLOADS, symbols, context)
|
||||
}
|
||||
conflictingDeclaration is FirClassLikeSymbol<*> &&
|
||||
conflictingDeclaration.getContainingClassSymbol(context.session) == null &&
|
||||
symbols.any { it is FirClassLikeSymbol<*> } -> {
|
||||
reporter.reportOn(source, FirErrors.PACKAGE_OR_CLASSIFIER_REDECLARATION, symbols, context)
|
||||
}
|
||||
else -> {
|
||||
reporter.reportOn(source, FirErrors.REDECLARATION, symbols, context)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
@@ -501,6 +501,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PACKAGE_CANNOT_BE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PACKAGE_OR_CLASSIFIER_REDECLARATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PLATFORM_CLASS_MAPPED_TO_KOTLIN
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.COMPILER_REQUIRED_ANNOTATION_AMBIGUITY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.POTENTIALLY_NON_REPORTED_ANNOTATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRE_RELEASE_CLASS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED
|
||||
@@ -1800,6 +1801,8 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
map.put(CONFLICTING_OVERLOADS, "Conflicting overloads: {0}", SYMBOLS)
|
||||
map.put(REDECLARATION, "Conflicting declarations: {0}", SYMBOLS)
|
||||
map.put(PACKAGE_OR_CLASSIFIER_REDECLARATION, "Redeclaration: {0}", SYMBOLS)
|
||||
map.put(EXPECT_AND_ACTUAL_IN_THE_SAME_MODULE, "{0}: expect and corresponding actual are declared in the same module", DECLARATION_NAME)
|
||||
|
||||
map.put(METHOD_OF_ANY_IMPLEMENTED_IN_INTERFACE, "Interfaces cannot implement a method of 'Any'.")
|
||||
|
||||
// Invalid local declarations
|
||||
|
||||
Reference in New Issue
Block a user