[IR] Print annotation arguments in report of ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT
Now IR checker is not duplicated by FIR checker reporting, so it's useful to have more verbose report of annotations in diagnostic message. ^KT-62559
This commit is contained in:
committed by
Space Team
parent
ec7a2c20d1
commit
8f6b6e17be
+11
-4
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.ir.IrDiagnosticRenderers
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.classFqName
|
||||
import org.jetbrains.kotlin.ir.util.RenderIrElementVisitorForDiagnosticText
|
||||
import org.jetbrains.kotlin.platform.isCommon
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualAnnotationsIncompatibilityType
|
||||
import org.jetbrains.kotlin.resolve.multiplatform.ExpectActualCheckingCompatibility
|
||||
@@ -80,14 +80,21 @@ internal object IrActualizationDiagnosticRenderers {
|
||||
}
|
||||
val EXPECT_ACTUAL_ANNOTATION_INCOMPATIBILITY =
|
||||
Renderer { incompatibilityType: ExpectActualAnnotationsIncompatibilityType<IrConstructorCall> ->
|
||||
val expectAnnotationFqName = incompatibilityType.expectAnnotation.type.classFqName ?: "<unknown>"
|
||||
val expectAnnotation = ANNOTATION.render(incompatibilityType.expectAnnotation)
|
||||
val reason = when (incompatibilityType) {
|
||||
is ExpectActualAnnotationsIncompatibilityType.MissingOnActual -> "is missing on actual declaration"
|
||||
is ExpectActualAnnotationsIncompatibilityType.DifferentOnActual -> "has different arguments on actual declaration"
|
||||
is ExpectActualAnnotationsIncompatibilityType.DifferentOnActual -> {
|
||||
val actualAnnotation = ANNOTATION.render(incompatibilityType.actualAnnotation)
|
||||
"has different arguments on actual declaration: `$actualAnnotation`"
|
||||
}
|
||||
}
|
||||
"Annotation `$expectAnnotationFqName` $reason"
|
||||
"Annotation `$expectAnnotation` $reason"
|
||||
}
|
||||
|
||||
private val ANNOTATION = Renderer<IrConstructorCall> {
|
||||
"@" + RenderIrElementVisitorForDiagnosticText.renderAsAnnotation(it)
|
||||
}
|
||||
|
||||
@JvmField
|
||||
val MODULE_WITH_PLATFORM = Renderer<ModuleDescriptor> { module ->
|
||||
val platform = module.platform
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.utils.addToStdlib.ifTrue
|
||||
fun IrElement.render(options: DumpIrTreeOptions = DumpIrTreeOptions()) =
|
||||
accept(RenderIrElementVisitor(options), null)
|
||||
|
||||
class RenderIrElementVisitor(private val options: DumpIrTreeOptions = DumpIrTreeOptions()) :
|
||||
open class RenderIrElementVisitor(private val options: DumpIrTreeOptions = DumpIrTreeOptions()) :
|
||||
IrElementVisitor<String, Nothing?> {
|
||||
|
||||
private val variableNameData = VariableNameData(options.normalizeNames)
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.util
|
||||
|
||||
import org.jetbrains.kotlin.ir.expressions.IrClassReference
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
|
||||
import org.jetbrains.kotlin.ir.types.classOrFail
|
||||
|
||||
/**
|
||||
* This class can be used to beautifully print IR elements for compiler diagnostics, unlike
|
||||
* the original [RenderIrElementVisitor] which is used in tests for rendering tree dumps.
|
||||
*/
|
||||
class RenderIrElementVisitorForDiagnosticText private constructor() : RenderIrElementVisitor() {
|
||||
override fun visitClassReference(expression: IrClassReference, data: Nothing?): String {
|
||||
val className = expression.classType.classOrFail.owner.name
|
||||
return "$className::class"
|
||||
}
|
||||
|
||||
override fun visitGetEnumValue(expression: IrGetEnumValue, data: Nothing?): String {
|
||||
val className = expression.type.classOrFail.owner.name
|
||||
val entryName = expression.symbol.owner.name
|
||||
return "$className.$entryName"
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun renderAsAnnotation(annotation: IrConstructorCall): String {
|
||||
return RenderIrElementVisitorForDiagnosticText().renderAsAnnotation(annotation)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user