[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)
|
||||
}
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -19,11 +19,11 @@ expect fun kclassArg()
|
||||
|
||||
// MODULE: m1-jvm()()(m1-common)
|
||||
// FILE: jvm.kt
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("Ann; Ann; Annotation `kotlin.annotation.Target` is missing on actual declaration")!>actual annotation class Ann<!>
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("Ann; Ann; Annotation `@Target(allowedTargets = [AnnotationTarget.FUNCTION, AnnotationTarget.CLASS])` is missing on actual declaration")!>actual annotation class Ann<!>
|
||||
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("stringConcat; stringConcat; Annotation `Ann2` is missing on actual declaration")!>actual fun stringConcat() {}<!>
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("stringConcat; stringConcat; Annotation `@Ann2(s = '12')` is missing on actual declaration")!>actual fun stringConcat() {}<!>
|
||||
|
||||
// Not reported in K1, because supported starting from K2
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("onType; onType; Annotation `Ann2` is missing on actual declaration")!>actual fun onType(): Any? = null<!>
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("onType; onType; Annotation `@Ann2(s = '')` is missing on actual declaration")!>actual fun onType(): Any? = null<!>
|
||||
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("kclassArg; kclassArg; Annotation `Ann3` is missing on actual declaration")!>actual fun kclassArg() {}<!>
|
||||
<!ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT("kclassArg; kclassArg; Annotation `@Ann3(kclass = String::class)` is missing on actual declaration")!>actual fun kclassArg() {}<!>
|
||||
|
||||
+9
-9
@@ -1,26 +1,26 @@
|
||||
/jvm.kt:(94,114): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(94,114): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `OnClass` must be present with the same arguments on actual `OnClass`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(144,168): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(144,168): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `OnMember.onMember` must be present with the same arguments on actual `OnMember.onMember`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(196,244): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(196,244): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `ViaTypealias` must be present with the same arguments on actual `ViaTypealiasImpl`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(301,371): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(301,371): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `MemberScopeViaTypealias.foo` must be present with the same arguments on actual `MemberScopeViaTypealiasImpl.foo`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(373,427): warning: Annotation `WithArg` has different arguments on actual declaration.
|
||||
/jvm.kt:(373,427): warning: Annotation `@WithArg(s = 'str')` has different arguments on actual declaration: `@WithArg(s = 'other str')`.
|
||||
All annotations from expect `withDifferentArg` must be present with the same arguments on actual `withDifferentArg`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(429,468): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(429,468): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `inValueParam` must be present with the same arguments on actual `inValueParam`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(470,501): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(470,501): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `inTypeParam` must be present with the same arguments on actual `inTypeParam`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(503,535): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(503,535): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `<get-onGetter>` must be present with the same arguments on actual `<get-onGetter>`, otherwise they might behave incorrectly.
|
||||
|
||||
/jvm.kt:(537,569): warning: Annotation `Ann` is missing on actual declaration.
|
||||
/jvm.kt:(537,569): warning: Annotation `@Ann` is missing on actual declaration.
|
||||
All annotations from expect `onType` must be present with the same arguments on actual `onType`, otherwise they might behave incorrectly.
|
||||
|
||||
Reference in New Issue
Block a user