From 0c3d5c11b18ba04b3286b7e19992d9be37527b61 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 2 May 2023 15:02:20 +0200 Subject: [PATCH] [FIR] Render integer literal types as Int in diagnostic messages #KT-55662 Fixed --- .../diagnostics/FirErrorsDefaultMessages.kt | 6 +++--- .../kotlin/fir/renderer/ConeTypeRenderer.kt | 20 +++++++++++++------ .../ConeTypeRendererWithJavaFlexibleTypes.kt | 5 +++++ .../tests/PropertyInitializers.fir.kt | 13 ++++++++++++ .../diagnostics/tests/PropertyInitializers.kt | 7 +++++-- .../tests/PropertyInitializers.txt | 1 + 6 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt index 25972c6043e..b4d857bc205 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrorsDefaultMessages.kt @@ -1077,14 +1077,14 @@ object FirErrorsDefaultMessages : BaseDiagnosticRendererFactory() { "Intersection types are only supported for definitely non-nullable types: right part should be non-nullable Any" ) - map.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", TO_STRING, TO_STRING, NOT_RENDERED) + map.put(TYPE_MISMATCH, "Type mismatch: inferred type is {1} but {0} was expected", RENDER_TYPE, RENDER_TYPE, NOT_RENDERED) map.put( TYPE_INFERENCE_ONLY_INPUT_TYPES_ERROR, "Type inference failed. The value of the type parameter {0} should be mentioned in input types (argument types, receiver type or expected type). Try to specify it explicitly.", SYMBOL ) - map.put(THROWABLE_TYPE_MISMATCH, "Throwable type mismatch: actual type is {0}", TO_STRING, NOT_RENDERED) - map.put(CONDITION_TYPE_MISMATCH, "Condition type mismatch: inferred type is {0} but Boolean was expected", TO_STRING, NOT_RENDERED) + map.put(THROWABLE_TYPE_MISMATCH, "Throwable type mismatch: actual type is {0}", RENDER_TYPE, NOT_RENDERED) + map.put(CONDITION_TYPE_MISMATCH, "Condition type mismatch: inferred type is {0} but Boolean was expected", RENDER_TYPE, NOT_RENDERED) map.put( ARGUMENT_TYPE_MISMATCH, "Argument type mismatch: actual type is {1} but {0} was expected", diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRenderer.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRenderer.kt index 4a3b5f3ca27..bf85c13e520 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRenderer.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRenderer.kt @@ -126,12 +126,8 @@ open class ConeTypeRenderer { builder.append("Stub (subtyping): ${type.constructor.variable}") } - is ConeIntegerLiteralConstantType -> { - builder.append("ILT: ${type.value}") - } - - is ConeIntegerConstantOperatorType -> { - builder.append("IOT") + is ConeIntegerLiteralType -> { + render(type) } } if (type !is ConeFlexibleType && type !is ConeErrorType) { @@ -210,4 +206,16 @@ open class ConeTypeRenderer { } } } + + protected open fun render(type: ConeIntegerLiteralType) { + when (type) { + is ConeIntegerLiteralConstantType -> { + builder.append("ILT: ${type.value}") + } + + is ConeIntegerConstantOperatorType -> { + builder.append("IOT") + } + } + } } diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRendererWithJavaFlexibleTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRendererWithJavaFlexibleTypes.kt index 0f9f2e69fb1..e93c1038103 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRendererWithJavaFlexibleTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/renderer/ConeTypeRendererWithJavaFlexibleTypes.kt @@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.renderer import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.fir.types.ConeFlexibleType +import org.jetbrains.kotlin.fir.types.ConeIntegerLiteralType import org.jetbrains.kotlin.renderer.replacePrefixesInTypeRepresentations import org.jetbrains.kotlin.renderer.typeStringsDifferOnlyInNullability @@ -73,4 +74,8 @@ class ConeTypeRendererWithJavaFlexibleTypes : ConeTypeRenderer { return "ft<$lowerRendered, $upperRendered>" } + + override fun render(type: ConeIntegerLiteralType) { + render(type.getApproximatedType()) + } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt b/compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt new file mode 100644 index 00000000000..b781eed6699 --- /dev/null +++ b/compiler/testData/diagnostics/tests/PropertyInitializers.fir.kt @@ -0,0 +1,13 @@ +// WITH_STDLIB + +class Foo(val a: Int, b: Int) { + val c = a + b + + val d: Int + get() = a + + val e: Int + get() = b + + val map: Map = mapOf(1 to "hello") +} diff --git a/compiler/testData/diagnostics/tests/PropertyInitializers.kt b/compiler/testData/diagnostics/tests/PropertyInitializers.kt index 5cc3a808f9d..c7ff80f032e 100644 --- a/compiler/testData/diagnostics/tests/PropertyInitializers.kt +++ b/compiler/testData/diagnostics/tests/PropertyInitializers.kt @@ -1,4 +1,5 @@ -// FIR_IDENTICAL +// WITH_STDLIB + class Foo(val a: Int, b: Int) { val c = a + b @@ -7,4 +8,6 @@ class Foo(val a: Int, b: Int) { val e: Int get() = b -} \ No newline at end of file + + val map: Map = ; Map")!>mapOf(1 to "hello") +} diff --git a/compiler/testData/diagnostics/tests/PropertyInitializers.txt b/compiler/testData/diagnostics/tests/PropertyInitializers.txt index 40084ada367..b2aa010ba09 100644 --- a/compiler/testData/diagnostics/tests/PropertyInitializers.txt +++ b/compiler/testData/diagnostics/tests/PropertyInitializers.txt @@ -6,6 +6,7 @@ public final class Foo { public final val c: kotlin.Int public final val d: kotlin.Int public final val e: kotlin.Int + public final val map: kotlin.collections.Map public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String