From 30948269ddf2b7712eb5f49f140456793f5d7fed Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Mon, 9 Apr 2018 17:07:01 +0300 Subject: [PATCH] Minor: use enum for determining verbosity of ConstraintSystem render --- .../kotlin/diagnostics/rendering/Renderers.kt | 23 ++++++++++++++----- .../AbstractConstraintSystemTest.kt | 2 +- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt index ba45ed2d1e1..a86af0a68ee 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt @@ -533,26 +533,37 @@ object Renderers { @JvmField val RENDER_COLLECTION_OF_TYPES = ContextDependentRenderer> { 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() 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") diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt index 7e390ef547b..74caf625775 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt @@ -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 {