[FIR] Render integer literal types as Int in diagnostic messages

#KT-55662 Fixed
This commit is contained in:
Kirill Rakhman
2023-05-02 15:02:20 +02:00
committed by Space Team
parent cc87aabaec
commit 0c3d5c11b1
6 changed files with 41 additions and 11 deletions
@@ -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",
@@ -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")
}
}
}
}
@@ -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())
}
}
@@ -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() = <!UNRESOLVED_REFERENCE!>b<!>
val map: Map<String, Int> = <!INITIALIZER_TYPE_MISMATCH, TYPE_MISMATCH("kotlin/String; kotlin/Int"), TYPE_MISMATCH("kotlin/String; kotlin/Int"), TYPE_MISMATCH("kotlin/Int; kotlin/String"), TYPE_MISMATCH("kotlin/String; kotlin/Int"), TYPE_MISMATCH("kotlin/Int; kotlin/String")!>mapOf(1 to "hello")<!>
}
@@ -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() = <!UNRESOLVED_REFERENCE!>b<!>
}
val map: Map<String, Int> = <!TYPE_MISMATCH("String; Int"), TYPE_MISMATCH("Int; String"), TYPE_MISMATCH("Map<String, Int>; Map<String, String>")!>mapOf(1 to "hello")<!>
}
@@ -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<kotlin.String, kotlin.Int>
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