[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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user