From 0fdfb6b5db7c6939344efbb32edd7b362ac5acf7 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Mon, 11 May 2015 12:57:54 +0200 Subject: [PATCH] Render short names in constraint system tests --- .../kotlin/diagnostics/rendering/Renderers.kt | 11 ++++++----- .../checkStatus/conflictingConstraints.bounds | 2 +- .../constraintSystem/checkStatus/successful.bounds | 4 ++-- .../checkStatus/violatedUpperBound.bounds | 2 +- .../integerValueTypes/byteOverflow.bounds | 2 +- .../integerValueTypes/defaultLong.bounds | 2 +- .../integerValueTypes/numberAndAny.bounds | 4 ++-- .../integerValueTypes/numberAndString.bounds | 4 ++-- .../integerValueTypes/severalNumbers.bounds | 2 +- .../integerValueTypes/simpleByte.bounds | 4 ++-- .../integerValueTypes/simpleInt.bounds | 2 +- .../integerValueTypes/simpleShort.bounds | 4 ++-- .../severalVariables/simpleDependency.bounds | 9 ++++----- .../constraintSystem/AbstractConstraintSystemTest.kt | 3 ++- 14 files changed, 28 insertions(+), 27 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 45ab277a171..f08c04f856b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/Renderers.kt @@ -365,11 +365,12 @@ public object Renderers { public val RENDER_CONSTRAINT_SYSTEM: Renderer = Renderer { renderConstraintSystem(it, RENDER_TYPE_BOUNDS) } public val RENDER_CONSTRAINT_SYSTEM_SHORT: Renderer = Renderer { renderConstraintSystem(it, RENDER_TYPE_BOUNDS_SHORT) } - private fun renderTypeBounds(typeBounds: TypeBounds, renderPosition: Boolean): String { + private fun renderTypeBounds(typeBounds: TypeBounds, short: Boolean): String { val renderBound = { bound: Bound -> val arrow = if (bound.kind == LOWER_BOUND) ">: " else if (bound.kind == UPPER_BOUND) "<: " else ":= " - val type = arrow + RENDER_TYPE.render(bound.constrainingType) - if (renderPosition) type + '(' + bound.position + ')' else type + val renderer = if (short) DescriptorRenderer.SHORT_NAMES_IN_TYPES else DescriptorRenderer.FQ_NAMES_IN_TYPES + val renderedBound = arrow + renderer.renderType(bound.constrainingType) + if (short) renderedBound else renderedBound + '(' + bound.position + ')' } val typeVariableName = typeBounds.typeVariable.getName() return if (typeBounds.bounds.isEmpty()) { @@ -379,8 +380,8 @@ public object Renderers { "$typeVariableName ${StringUtil.join(typeBounds.bounds, renderBound, ", ")}" } - public val RENDER_TYPE_BOUNDS: Renderer = Renderer { renderTypeBounds(it, renderPosition = true) } - public val RENDER_TYPE_BOUNDS_SHORT: Renderer = Renderer { renderTypeBounds(it, renderPosition = false) } + public val RENDER_TYPE_BOUNDS: Renderer = Renderer { renderTypeBounds(it, short = false) } + public val RENDER_TYPE_BOUNDS_SHORT: Renderer = Renderer { renderTypeBounds(it, short = true) } private fun renderDebugMessage(message: String, inferenceErrorData: InferenceErrorData) = StringBuilder { append(message) diff --git a/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds b/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds index 67adbc29304..ca0e8e1b407 100644 --- a/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds +++ b/compiler/testData/constraintSystem/checkStatus/conflictingConstraints.bounds @@ -4,7 +4,7 @@ SUBTYPE T Int SUPERTYPE T String type parameter bounds: -T <: kotlin.Int, >: kotlin.String +T <: Int, >: String status: -hasCannotCaptureTypesError: false diff --git a/compiler/testData/constraintSystem/checkStatus/successful.bounds b/compiler/testData/constraintSystem/checkStatus/successful.bounds index ee2bdcc9cfa..5fc00e55296 100644 --- a/compiler/testData/constraintSystem/checkStatus/successful.bounds +++ b/compiler/testData/constraintSystem/checkStatus/successful.bounds @@ -4,7 +4,7 @@ SUBTYPE T Int SUPERTYPE T Int type parameter bounds: -T <: kotlin.Int, >: kotlin.Int +T <: Int, >: Int status: -hasCannotCaptureTypesError: false @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Int +T=Int \ No newline at end of file diff --git a/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds b/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds index 7df267a863a..2dd0cc822c1 100644 --- a/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds +++ b/compiler/testData/constraintSystem/checkStatus/violatedUpperBound.bounds @@ -4,7 +4,7 @@ SUBTYPE T Int SUBTYPE T String weak type parameter bounds: -T <: kotlin.Int, <: kotlin.String +T <: Int, <: String status: -hasCannotCaptureTypesError: false diff --git a/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds b/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds index 2b12eb4e771..7a95617b2aa 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/byteOverflow.bounds @@ -4,7 +4,7 @@ SUPERTYPE T IntegerValueType(1000) SUBTYPE T Byte type parameter bounds: -T >: IntegerValueType(1000), <: kotlin.Byte +T >: IntegerValueType(1000), <: Byte status: -hasCannotCaptureTypesError: false diff --git a/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds b/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds index 366890eab70..3d82f18077a 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/defaultLong.bounds @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Long +T=Long \ No newline at end of file diff --git a/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds b/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds index 476a7a7812c..909959cb637 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/numberAndAny.bounds @@ -4,7 +4,7 @@ SUPERTYPE T IntegerValueType(1) SUBTYPE T Any type parameter bounds: -T >: IntegerValueType(1), <: kotlin.Any +T >: IntegerValueType(1), <: Any status: -hasCannotCaptureTypesError: false @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Int +T=Int \ No newline at end of file diff --git a/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds b/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds index e490165dabd..ab339288908 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/numberAndString.bounds @@ -4,7 +4,7 @@ SUPERTYPE T IntegerValueType(1) SUPERTYPE T String type parameter bounds: -T >: IntegerValueType(1), >: kotlin.String +T >: IntegerValueType(1), >: String status: -hasCannotCaptureTypesError: false @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Comparable +T=Comparable \ No newline at end of file diff --git a/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds b/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds index baa972d9ddb..2ac118165c5 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/severalNumbers.bounds @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Int +T=Int \ No newline at end of file diff --git a/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds b/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds index 56018383515..6e09380a9ed 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/simpleByte.bounds @@ -4,7 +4,7 @@ SUPERTYPE T IntegerValueType(1) SUBTYPE T Byte type parameter bounds: -T >: IntegerValueType(1), <: kotlin.Byte +T >: IntegerValueType(1), <: Byte status: -hasCannotCaptureTypesError: false @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Byte +T=Byte \ No newline at end of file diff --git a/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds b/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds index fc8290b88cd..5271316e2c3 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/simpleInt.bounds @@ -16,4 +16,4 @@ status: -isSuccessful: true result: -T=kotlin.Int +T=Int \ No newline at end of file diff --git a/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds b/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds index 846da5f8405..44f7762efa6 100644 --- a/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds +++ b/compiler/testData/constraintSystem/integerValueTypes/simpleShort.bounds @@ -4,7 +4,7 @@ SUPERTYPE T IntegerValueType(1) SUBTYPE T Short type parameter bounds: -T >: IntegerValueType(1), <: kotlin.Short +T >: IntegerValueType(1), <: Short status: -hasCannotCaptureTypesError: false @@ -17,4 +17,4 @@ status: -isSuccessful: true result: -T=kotlin.Short +T=Short \ No newline at end of file diff --git a/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds b/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds index 7d89b1b9557..6b8c2fac7e7 100644 --- a/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds +++ b/compiler/testData/constraintSystem/severalVariables/simpleDependency.bounds @@ -3,8 +3,8 @@ VARIABLES T P SUBTYPE T Int type parameter bounds: -T <: kotlin.Int -P <: kotlin.Int +T <: Int +P <: Int status: -hasCannotCaptureTypesError: false @@ -17,6 +17,5 @@ status: -isSuccessful: true result: -T=kotlin.Int -P=kotlin.Int - +T=Int +P=Int \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt b/compiler/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt index e8065aec277..319527fc06f 100644 --- a/compiler/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/resolve/constraintSystem/AbstractConstraintSystemTest.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve.constraintSystem import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.diagnostics.rendering.Renderers +import org.jetbrains.kotlin.renderer.DescriptorRenderer import org.jetbrains.kotlin.resolve.TypeResolver import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemImpl import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.SPECIAL @@ -108,7 +109,7 @@ abstract public class AbstractConstraintSystemTest() : JetLiteFixture() { for ((typeParameter, variance) in typeParameterDescriptors) { val parameterType = testDeclarations.getType(typeParameter.getName().asString()) val resultType = resultingSubstitutor.substitute(parameterType, variance) - result append "${typeParameter.getName()}=${resultType?.let{ Renderers.RENDER_TYPE.render(it) }}\n" + result append "${typeParameter.getName()}=${resultType?.let{ DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) }}\n" } JetTestUtils.assertEqualsToFile(file, "${getConstraintsText(fileText)}${resultingStatus}\n\n${result}\n")