[FIR] Add toString() methods to some ConeSubstitutor implementation

This is needed only for pleasant debugging
This commit is contained in:
Dmitriy Novozhilov
2023-06-07 15:42:38 +03:00
committed by Space Team
parent ba6f8e9b23
commit 8b7cfcda10
3 changed files with 36 additions and 1 deletions
@@ -55,7 +55,11 @@ data class ConeStubTypeConstructor(
val variable: ConeTypeVariable,
val isTypeVariableInSubtyping: Boolean,
val isForFixation: Boolean = false,
) : TypeConstructorMarker
) : TypeConstructorMarker {
override fun toString(): String {
return "Stub(${variable.typeConstructor.debugName})"
}
}
sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker,
ConeSimpleKotlinType() {
@@ -183,6 +183,10 @@ data class ChainedSubstitutor(private val first: ConeSubstitutor, private val se
first.substituteOrNull(type)?.let { return second.substituteOrSelf(it) }
return second.substituteOrNull(type)
}
override fun toString(): String {
return "$first then $second"
}
}
fun ConeSubstitutor.chain(other: ConeSubstitutor): ConeSubstitutor {
@@ -220,6 +224,12 @@ class ConeSubstitutorByMap(
}
override fun hashCode() = hashCode
override fun toString(): String {
return substitution.entries.joinToString(prefix = "{", postfix = "}", separator = " | ") { (param, type) ->
"${param.name} -> ${type.renderForDebugging()}"
}
}
}
class ConeRawScopeSubstitutor(
@@ -292,6 +302,12 @@ internal class ConeTypeSubstitutorByTypeConstructor(
val approximatedIntegerLiteralType = if (approximateIntegerLiterals) new.approximateIntegerLiteralType() else new
return approximatedIntegerLiteralType.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
}
override fun toString(): String {
return map.entries.joinToString(prefix = "{", postfix = "}", separator = " | ") { (constructor, type) ->
"$constructor -> ${type.renderForDebugging()}"
}
}
}
// Note: builder inference uses TypeSubstitutorByTypeConstructor for not fixed type substitution
@@ -304,6 +320,13 @@ class NotFixedTypeToVariableSubstitutorForDelegateInference(
if (type.constructor.isTypeVariableInSubtyping) return null
return bindings[type.constructor.variable].updateNullabilityIfNeeded(type)
}
override fun toString(): String {
return bindings.entries.joinToString(prefix = "{", postfix = "}", separator = " | ") { (variable, type) ->
require(variable is ConeTypeVariable)
"TV(${variable.typeConstructor.debugName}) -> ${type.renderForDebugging()}"
}
}
}
class ConeStubAndTypeVariableToErrorTypeSubstitutor(
@@ -328,6 +351,10 @@ class ConeStubAndTypeVariableToErrorTypeSubstitutor(
else -> null
}
}
override fun toString(): String {
return "{<Stub type> -> <Error type>}"
}
}
fun ConeSubstitutor.replaceStubsAndTypeVariablesToErrors(
@@ -30,4 +30,8 @@ private class TypeVariableTypeRemovingSubstitutor(typeContext: ConeTypeContext)
}
return ConeErrorType(ConeUnknownLambdaParameterTypeDiagnostic())
}
override fun toString(): String {
return "{<Type variable> -> <Error type>}"
}
}