[IR] Fix arguments of backend error messages

#KT-57662 Fixed
This commit is contained in:
Kirill Rakhman
2023-03-30 13:32:07 +02:00
committed by Space Team
parent 674397be82
commit 4dfef6ba6f
3 changed files with 23 additions and 8 deletions
@@ -8,15 +8,15 @@ package org.jetbrains.kotlin.backend.common
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryToRendererMap
import org.jetbrains.kotlin.diagnostics.error1
import org.jetbrains.kotlin.diagnostics.error2
import org.jetbrains.kotlin.diagnostics.rendering.BaseDiagnosticRendererFactory
import org.jetbrains.kotlin.diagnostics.rendering.CommonRenderers.STRING
import org.jetbrains.kotlin.diagnostics.rendering.Renderers.MODULE_WITH_PLATFORM
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
object CommonBackendErrors {
val NO_ACTUAL_FOR_EXPECT by error1<PsiElement, ModuleDescriptor>()
val MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED by error1<PsiElement, String>()
val NO_ACTUAL_FOR_EXPECT by error2<PsiElement, String, ModuleDescriptor>()
val MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED by error2<PsiElement, String, String>()
init {
RootDiagnosticRendererFactory.registerFactory(KtDefaultCommonBackendErrorMessages)
@@ -25,7 +25,17 @@ object CommonBackendErrors {
object KtDefaultCommonBackendErrorMessages : BaseDiagnosticRendererFactory() {
override val MAP = KtDiagnosticFactoryToRendererMap("KT").also { map ->
map.put(CommonBackendErrors.NO_ACTUAL_FOR_EXPECT, "Expected {0} has no actual declaration in module {1}", MODULE_WITH_PLATFORM)
map.put(CommonBackendErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED, "{0} must override {1} because it inherits multiple interface methods of it", STRING)
map.put(
CommonBackendErrors.NO_ACTUAL_FOR_EXPECT,
"Expected {0} has no actual declaration in module {1}",
STRING,
MODULE_WITH_PLATFORM,
)
map.put(
CommonBackendErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED,
"{0} must override {1} because it inherits multiple interface methods of it",
STRING,
STRING,
)
}
}
@@ -150,11 +150,15 @@ private fun appendElementFullName(
@OptIn(ObsoleteDescriptorBasedAPI::class)
fun KtDiagnosticReporterWithImplicitIrBasedContext.reportMissingActual(irDeclaration: IrDeclaration) {
at(irDeclaration).report(CommonBackendErrors.NO_ACTUAL_FOR_EXPECT, irDeclaration.module)
at(irDeclaration).report(
CommonBackendErrors.NO_ACTUAL_FOR_EXPECT,
(irDeclaration as? IrDeclarationWithName)?.name?.asString().orEmpty(),
irDeclaration.module
)
}
internal fun IrElement.containsOptionalExpectation(): Boolean {
return this is IrClass &&
this.kind == ClassKind.ANNOTATION_CLASS &&
this.hasAnnotation(OptionalAnnotationUtil.OPTIONAL_EXPECTATION_FQ_NAME)
}
}
@@ -89,6 +89,7 @@ class MissingFakeOverridesAdder(
} else {
diagnosticsReporter.at(declaration).report(
CommonBackendErrors.MANY_INTERFACES_MEMBER_NOT_IMPLEMENTED,
declaration.name.asString(),
(actualMember as IrDeclarationWithName).name.asString()
)
}
@@ -141,4 +142,4 @@ private fun createFakeOverrideFunction(
it.overriddenSymbols = listOf(actualFunction.symbol)
it.attributeOwnerId = it
it.correspondingPropertySymbol = correspondingPropertySymbol
}
}