[FIR] Report list of conflicting symbols in REDECLARATION and CONFLICTING_OVERLOADS
This commit is contained in:
committed by
TeamCityServer
parent
7a4625b70b
commit
d696a488b5
+2
-2
@@ -245,10 +245,10 @@ val DIAGNOSTICS_LIST = DiagnosticListBuilder.buildDiagnosticList {
|
||||
group("Redeclarations") {
|
||||
val MANY_COMPANION_OBJECTS by error<FirSourceElement, PsiElement>()
|
||||
val CONFLICTING_OVERLOADS by error<FirSourceElement, PsiElement>(PositioningStrategy.DECLARATION_SIGNATURE_OR_DEFAULT) {
|
||||
parameter<String>("conflictingOverloads") // TODO use Collection<Symbol> instead of String
|
||||
parameter<Collection<AbstractFirBasedSymbol<*>>>("conflictingOverloads")
|
||||
}
|
||||
val REDECLARATION by error<FirSourceElement, PsiElement>() {
|
||||
parameter<String>("conflictingDeclaration") // TODO use Collection<Symbol> instead of String
|
||||
parameter<Collection<AbstractFirBasedSymbol<*>>>("conflictingDeclarations")
|
||||
}
|
||||
val ANY_METHOD_IMPLEMENTED_IN_INTERFACE by error<FirSourceElement, PsiElement>()
|
||||
}
|
||||
|
||||
+2
-2
@@ -178,8 +178,8 @@ object FirErrors {
|
||||
|
||||
// Redeclarations
|
||||
val MANY_COMPANION_OBJECTS by error0<FirSourceElement, PsiElement>()
|
||||
val CONFLICTING_OVERLOADS by error1<FirSourceElement, PsiElement, String>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
val REDECLARATION by error1<FirSourceElement, PsiElement, String>()
|
||||
val CONFLICTING_OVERLOADS by error1<FirSourceElement, PsiElement, Collection<AbstractFirBasedSymbol<*>>>(SourceElementPositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT)
|
||||
val REDECLARATION by error1<FirSourceElement, PsiElement, Collection<AbstractFirBasedSymbol<*>>>()
|
||||
val ANY_METHOD_IMPLEMENTED_IN_INTERFACE by error0<FirSourceElement, PsiElement>()
|
||||
|
||||
// Invalid local declarations
|
||||
|
||||
+9
-7
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSymbolOwner
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.FirDeclarationInspector
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
@@ -13,6 +14,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol
|
||||
|
||||
object FirConflictsChecker : FirBasicDeclarationChecker() {
|
||||
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
@@ -24,22 +26,22 @@ object FirConflictsChecker : FirBasicDeclarationChecker() {
|
||||
else -> return
|
||||
}
|
||||
|
||||
inspector.functionDeclarations.forEachNonSingle { it, hint ->
|
||||
reporter.reportOn(it.source, FirErrors.CONFLICTING_OVERLOADS, hint, context)
|
||||
inspector.functionDeclarations.forEachNonSingle { it, symbols ->
|
||||
reporter.reportOn(it.source, FirErrors.CONFLICTING_OVERLOADS, symbols, context)
|
||||
}
|
||||
|
||||
inspector.otherDeclarations.forEachNonSingle { it, hint ->
|
||||
reporter.reportOn(it.source, FirErrors.REDECLARATION, hint, context)
|
||||
inspector.otherDeclarations.forEachNonSingle { it, symbols ->
|
||||
reporter.reportOn(it.source, FirErrors.REDECLARATION, symbols, context)
|
||||
}
|
||||
}
|
||||
|
||||
private fun Map<String, List<FirDeclaration>>.forEachNonSingle(action: (FirDeclaration, String) -> Unit) {
|
||||
private fun Map<String, List<FirDeclaration>>.forEachNonSingle(action: (FirDeclaration, Collection<AbstractFirBasedSymbol<*>>) -> Unit) {
|
||||
for (value in values) {
|
||||
if (value.size > 1) {
|
||||
val hint = value.joinToString { that -> that.toString() }
|
||||
val symbols = value.mapNotNull { (it as? FirSymbolOwner<*>)?.symbol }
|
||||
|
||||
value.forEach {
|
||||
action(it, hint)
|
||||
action(it, symbols)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -402,8 +402,8 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension {
|
||||
|
||||
// Redeclarations
|
||||
map.put(MANY_COMPANION_OBJECTS, "Only one companion object is allowed per class")
|
||||
map.put(CONFLICTING_OVERLOADS, "Conflicting overloads: {0}", TO_STRING) // *
|
||||
map.put(REDECLARATION, "Conflicting declarations: {0}", TO_STRING) // *
|
||||
map.put(CONFLICTING_OVERLOADS, "Conflicting overloads: {0}", SYMBOLS) // *
|
||||
map.put(REDECLARATION, "Conflicting declarations: {0}", SYMBOLS) // *
|
||||
map.put(ANY_METHOD_IMPLEMENTED_IN_INTERFACE, "An interface may not implement a method of 'Any'") // &
|
||||
|
||||
// Invalid local declarations
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ object FirDiagnosticRenderers {
|
||||
}
|
||||
|
||||
val SYMBOLS = Renderer { symbols: Collection<AbstractFirBasedSymbol<*>> ->
|
||||
symbols.joinToString(prefix = "[", postfix = "]", separator = ",", limit = 3, truncated = "...") { symbol ->
|
||||
symbols.joinToString(prefix = "[", postfix = "]", separator = ", ", limit = 3, truncated = "...") { symbol ->
|
||||
SYMBOL.render(symbol)
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -731,14 +731,18 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
}
|
||||
add(FirErrors.CONFLICTING_OVERLOADS) { firDiagnostic ->
|
||||
ConflictingOverloadsImpl(
|
||||
firDiagnostic.a,
|
||||
firDiagnostic.a.map { abstractFirBasedSymbol ->
|
||||
firSymbolBuilder.buildSymbol(abstractFirBasedSymbol.fir as FirDeclaration)
|
||||
},
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.REDECLARATION) { firDiagnostic ->
|
||||
RedeclarationImpl(
|
||||
firDiagnostic.a,
|
||||
firDiagnostic.a.map { abstractFirBasedSymbol ->
|
||||
firSymbolBuilder.buildSymbol(abstractFirBasedSymbol.fir as FirDeclaration)
|
||||
},
|
||||
firDiagnostic as FirPsiDiagnostic<*>,
|
||||
token,
|
||||
)
|
||||
|
||||
+2
-2
@@ -521,12 +521,12 @@ sealed class KtFirDiagnostic<PSI: PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
|
||||
abstract class ConflictingOverloads : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = ConflictingOverloads::class
|
||||
abstract val conflictingOverloads: String
|
||||
abstract val conflictingOverloads: List<KtSymbol>
|
||||
}
|
||||
|
||||
abstract class Redeclaration : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = Redeclaration::class
|
||||
abstract val conflictingDeclaration: String
|
||||
abstract val conflictingDeclarations: List<KtSymbol>
|
||||
}
|
||||
|
||||
abstract class AnyMethodImplementedInInterface : KtFirDiagnostic<PsiElement>() {
|
||||
|
||||
+2
-2
@@ -830,7 +830,7 @@ internal class ManyCompanionObjectsImpl(
|
||||
}
|
||||
|
||||
internal class ConflictingOverloadsImpl(
|
||||
override val conflictingOverloads: String,
|
||||
override val conflictingOverloads: List<KtSymbol>,
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.ConflictingOverloads(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
@@ -838,7 +838,7 @@ internal class ConflictingOverloadsImpl(
|
||||
}
|
||||
|
||||
internal class RedeclarationImpl(
|
||||
override val conflictingDeclaration: String,
|
||||
override val conflictingDeclarations: List<KtSymbol>,
|
||||
firDiagnostic: FirPsiDiagnostic<*>,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.Redeclaration(), KtAbstractFirDiagnostic<PsiElement> {
|
||||
|
||||
Reference in New Issue
Block a user