Minor: use enum for determining verbosity of ConstraintSystem render
This commit is contained in:
@@ -533,26 +533,37 @@ object Renderers {
|
||||
@JvmField
|
||||
val RENDER_COLLECTION_OF_TYPES = ContextDependentRenderer<Collection<KotlinType>> { types, context -> renderTypes(types, context) }
|
||||
|
||||
fun renderConstraintSystem(constraintSystem: ConstraintSystem, shortTypeBounds: Boolean): String {
|
||||
enum class ConstraintSystemRenderingVerbosity {
|
||||
COMPACT,
|
||||
DEBUG, // Includes type bounds positions, types are rendered with FQNs instead of short names
|
||||
}
|
||||
|
||||
fun renderConstraintSystem(constraintSystem: ConstraintSystem, verbosity: ConstraintSystemRenderingVerbosity): String {
|
||||
val typeBounds = linkedSetOf<TypeBounds>()
|
||||
for (variable in constraintSystem.typeVariables) {
|
||||
typeBounds.add(constraintSystem.getTypeBounds(variable))
|
||||
}
|
||||
|
||||
return "type parameter bounds:\n" +
|
||||
StringUtil.join(typeBounds, { renderTypeBounds(it, short = shortTypeBounds) }, "\n") + "\n\n" + "status:\n" +
|
||||
StringUtil.join(typeBounds, { renderTypeBounds(it, verbosity) }, "\n") + "\n\n" + "status:\n" +
|
||||
ConstraintsUtil.getDebugMessageForStatus(constraintSystem.status)
|
||||
}
|
||||
|
||||
private fun renderTypeBounds(typeBounds: TypeBounds, short: Boolean): String {
|
||||
private fun renderTypeBounds(typeBounds: TypeBounds, verbosity: ConstraintSystemRenderingVerbosity): String {
|
||||
val renderBound = { bound: Bound ->
|
||||
val arrow = when (bound.kind) {
|
||||
LOWER_BOUND -> ">: "
|
||||
UPPER_BOUND -> "<: "
|
||||
else -> ":= "
|
||||
}
|
||||
val renderer = if (short) DescriptorRenderer.SHORT_NAMES_IN_TYPES else DescriptorRenderer.FQ_NAMES_IN_TYPES
|
||||
val renderer = if (verbosity == ConstraintSystemRenderingVerbosity.COMPACT)
|
||||
DescriptorRenderer.SHORT_NAMES_IN_TYPES
|
||||
else
|
||||
DescriptorRenderer.FQ_NAMES_IN_TYPES
|
||||
|
||||
val renderedBound = arrow + renderer.renderType(bound.constrainingType) + if (!bound.isProper) "*" else ""
|
||||
if (short) renderedBound else renderedBound + '(' + bound.position + ')'
|
||||
|
||||
if (verbosity == ConstraintSystemRenderingVerbosity.COMPACT) renderedBound else renderedBound + '(' + bound.position + ')'
|
||||
}
|
||||
val typeVariableName = typeBounds.typeVariable.name
|
||||
return if (typeBounds.bounds.isEmpty()) {
|
||||
@@ -564,7 +575,7 @@ object Renderers {
|
||||
private fun debugMessage(message: String, inferenceErrorData: InferenceErrorData) = buildString {
|
||||
append(message)
|
||||
append("\nConstraint system: \n")
|
||||
append(renderConstraintSystem(inferenceErrorData.constraintSystem, false))
|
||||
append(renderConstraintSystem(inferenceErrorData.constraintSystem, ConstraintSystemRenderingVerbosity.DEBUG))
|
||||
append("\nDescriptor:\n")
|
||||
append(inferenceErrorData.descriptor)
|
||||
append("\nExpected type:\n")
|
||||
|
||||
+1
-1
@@ -108,7 +108,7 @@ abstract class AbstractConstraintSystemTest : KotlinTestWithEnvironment() {
|
||||
|
||||
val system = builder.build()
|
||||
|
||||
val resultingStatus = Renderers.renderConstraintSystem(system, shortTypeBounds = true)
|
||||
val resultingStatus = Renderers.renderConstraintSystem(system, Renderers.ConstraintSystemRenderingVerbosity.COMPACT)
|
||||
|
||||
val resultingSubstitutor = system.resultingSubstitutor
|
||||
val result = typeParameterDescriptors.map {
|
||||
|
||||
Reference in New Issue
Block a user